2015-10-22 70 views
1

在PowerShell中,远程运行的进程(软件安装):WMICLASS.Create(),返回变量?

$computers = Get-Content "C:\computer.txt" 

foreach ($computer in $computers) { 


#The location of the file 
    $Install = "\\$computer\C$\Software" 

#The Install string can have commands aswell 
    $InstallString = "$Install\IE11-Windows6.1-x64-en-us.exe $arguments" 

    ([WMICLASS]"\\$computer\ROOT\CIMV2:Win32_Process").Create($InstallString) 
#Output the install result to your Local C Drive 
    Out-File -FilePath c:\installed.txt -Append -InputObject "$computer"} 

有没有办法返回变量或本安装状态?或者等到这个过程完成了?

回答

0

本地,您可以使用Wait-Process

$InstallProcess = ([WMICLASS]"Win32_Process").Create($InstallString) 
Wait-Process -Id $InstallProcess.ProcessId 

不幸的是,Wait-Process不支持远程处理。


这里是一个穷人的remote equivalent using Get-Process

$InstallProcess = ([WMICLASS]"\\$computer\ROOT\CIMV2:Win32_Process").Create($InstallString) 
do { Get-Process -Id $InstallProcess.ProcessId -ComputerName $computer } while ($?) 
+0

我尝试这一点,但有一个不过程中发现的。你确定这可以在远程PC上工作,或者是'Wait-Process'搜索本地PC吗? – Zeno

+0

@Zeno对不起,没有注意到,更新回答 –

+0

也没有运气,这是返回'Get-Process:无法连接到远程机器.'即使该过程确实开始 – Zeno