2017-11-06 15 views
0

두 번 클릭 할 수있는 스크립트가 있으며 관리자로 다른 스크립트가 열립니다. 몇 가지만 있지만 모든 것은 작동하지 않습니다. 한 스크립트의 경우 다음 창을 연 다음 바로 닫습니다. MYPATH \ InstallClient.ps1에서Powershell 스크립트가 다른 스크립트를 관리자로 엽니 다.

: 다른, 나는이 오류가 33 문자를 : 78 + ... tall_x64.msi "-force -recurse -ErrorAction 정지 #Cleans 파일 밖으로 ... + ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ 문자열에 터미네이터가 없습니다 : ". MYPATH \ InstallClient.ps1에서 : 27 char : 31 + ForEach ($ 컴퓨터 $ 항목) {beginstart foreach 루프 + ~ 문 블록 또는 형식 정의에서 '}'를 닫지 않았습니다. + CategoryInfo : ParserError : (: [], ParentContainsErrorRecordException + FullyQualifiedErrorId : 아래

가 관리자로 스크립트를 열 수있는 스크립트입니다 TerminatorExpectedAtEndOfString 것은 :
Function Get-FileName($initialDirectory) 
 
{ 
 
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null 
 

 
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog 
 
$OpenFileDialog.initialDirectory = $initialDirectory 
 
$OpenFileDialog.filter = "PS1 (*.ps1)| *.ps1" 
 
$OpenFileDialog.ShowDialog() | Out-Null 
 
$OpenFileDialog.filename 
 
} 
 
$inputfile = Get-FileName "MYPATH\Scripts" 
 
powershell.exe -noprofile -command "&{start-process powershell -ArgumentList '-NoExit -noprofile -file $inputfile' -verb RunAs}"

이 스크립트입니다 그것을 열려고 시도하는 동안 이전 오류를 제공합니다.

Function Get-FileName($initialDirectory) #Function to choose a file 
 
{ 
 
    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null 
 
    
 
    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog 
 
    $OpenFileDialog.initialDirectory = $initialDirectory 
 
    $OpenFileDialog.filter = "MSI (*.msi)| *.msi" #type of files that will be available for selection 
 
    $OpenFileDialog.ShowDialog() | Out-Null 
 
    $OpenFileDialog.filename 
 
} 
 
$inputfile = Get-FileName "MyPath" #Directory that is going to open to select a file from 
 

 
Function Get-FileName($initialDirectory) #Function to choose a file 
 
{ 
 
    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null 
 
    
 
    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog 
 
    $OpenFileDialog.initialDirectory = $initialDirectory 
 
    $OpenFileDialog.filter = "CSV (*.csv)| *.csv" #type of files that will be available for selection 
 
    $OpenFileDialog.ShowDialog() | Out-Null 
 
    $OpenFileDialog.filename 
 
} 
 
$inputfile1 = Get-FileName "MyPath\ServerLists" 
 
$computers = import-csv $inputfile1 
 

 
ForEach ($entry in $computers){ #start of foreach loop 
 
$computername = $entry.computernames #this saves the single entry under computernames for each entry in csv file 
 
Copy-item $inputfile -container -recurse \\$computername\C$\windows\temp #this copies the msi file that we selected to the computer entry called from the csv file's temp folder 
 
Invoke-Command -Computername $computername –ScriptBlock {Start-process -Wait "C:\windows\temp\ShadowSuiteClientInstall_x64.msi"} | out-null #This starts the msi file that we just copied and waits for the installation to be completed before moving on 
 
If($?){ #If the last command was successful 
 
Echo "Installed ShadowSuiteClientInstall_x64 on $computername." 
 
Remove-Item "\\$computername\C$\windows\temp\ShadowSuiteClientInstall_x64.msi" -force -recurse -ErrorAction Stop #Cleans out the file we copied into the temp folder 
 
} 
 
}

아무도 아이디어가 없지만이 스크립트에서이 오류가 발생하고 즉시 실행하지 않고 다른 스크립트를 닫을 수 있습니까? 누구든지 스크립트를 탐색하고 관리자로 열어 볼 수있는 더 나은 방법이 있습니까?

답변

0

좋습니다. 알아 냈습니다. 필자는이 스크립트를 powershell ISE에 로딩했고 잘못 컴파일하는 것을 보았습니다. Scriptblock을 scriptblock 앞에있는 대신에 ae 기호로 바꾸었다. 이상한 AF IMO이지만 괜찮습니다. ISE에서 수정했습니다.이 같은 이상한 컴파일 오류로 어려움을 겪고있는 누구에게나 추천합니다.