मेरे पास एक पावरशेल कोड है जिसे मैं powershell.exe
के माध्यम से कॉल कर रहा हूं। कोड कुछ सत्यापन करता है और फिर वास्तविक कार्य करने के लिए मुख्य स्क्रिप्ट को कॉल करता है।
नीचे कोड है:
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command {
$trademark = 'MMFSL'
$product = 'OSHardening'
$version = '3.0'
Add-Type -AssemblyName System.Windows.Forms
#Checks if the current powershell session is running in Administrative Mode
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (!($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) {
[System.Windows.Forms.MessageBox]::Show('Please run the file using Run as Administrator', "$($trademark)-$($product)-v$($version)", 'Ok', 'Error')
break;
}
Expand-Archive -Path .\Windows.zip -DestinationPath $env:ProgramData\$($trademark)\$($product)\$($version) -Force
Set-Location -Path $env:ProgramData\$($trademark)\$($product)\$($version)
.\main.ps1
}
नीचे त्रुटि संदेश है:
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command { Missing closing '}' in statement block or type definition. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingEndCurlyBrace
0
Rajiv Iyer
15 जुलाई 2019, 17:15
1 उत्तर
सबसे बढ़िया उत्तर
@ JS2010 के लिए धन्यवाद; मैंने अर्धविराम (;) जोड़कर कोड को एक पंक्ति में स्वरूपित किया। साथ ही, "& { code }"
के अंतर्गत कोड जोड़ा
नीचे संशोधित कोड है:
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {$trademark = 'MMFSL';$product = 'OSHardening';$version = '3.0';Add-Type -AssemblyName System.Windows.Forms;$PCWD = (Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain;if($PCWD -eq $true){[System.Windows.Forms.MessageBox]::Show('This is application is supported on Workgroup/Non-Domain Joined computers only.', "$($trademark) + '-' + $($product) + '-v' + $($version)", 'Ok', 'Error');break;}elseif ($PCWD -eq $false){Expand-Archive -Path .\Windows.zip -DestinationPath $env:ProgramData\$($trademark)\$($product)\$($version) -Force;Set-Location -Path $env:ProgramData\$($trademark)\$($product)\$($version);Invoke-Expression -Command .\main.ps1;}}"
0
Rajiv Iyer
16 जुलाई 2019, 10:17