【发布时间】:2018-06-25 15:31:38
【问题描述】:
我能够将所有 Patch 和 exe 从一台服务器复制到具有 this solution 的服务器列表 现在我正在尝试在远程服务器上的目标文件夹中远程安装所有补丁和 exe。 使用
$comname = Get-Content -Path ‘H:\InstallationFiles\server.txt’
$fname = Get-ChildItem ‘H:\InstallationFiles\Patch’ -Recurse -force | select-object FullName
Set-Item wsman:\localhost\client\trustedhosts * -Force
Foreach($sname in $comname){
Foreach($installpath in $fname){
$newproc=([WMICLASS]”\\$_\root\cimv2:win32_Process”).Create(“$installpath /s”)
If($newproc.ReturnValue -eq 0){
Write-Host $_ $newproc.ProcessID
}
Else {
Write-Host $_ Process Create failed with $newproc.ReturnValue
}
}
}
但我收到以下错误
Process Create failed with
Cannot convert value “\\\root\cimv2:win32_Process” to type “System.Management.ManagementClass”. Error: “Invalid parameter “
At H:/InstallationFiles/installfiletoserver.ps1:15 char:9
+ $newproc=([WMICLASS]”\\$_\root\cimv2:win32_Process”).Create(“$installFil ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [], Runtime.Exception
+ FullyQualfiedErrorId : InvalidCastToWMIClass
即使我尝试使用 Invoke-command,但也失败了。
Invoke-command -ComputerName $sname -ScriptBlock {
Start-Process $installpath -ArgumentList ‘/silent’ -wait
}
调用命令失败
[servername] Connection to remote server servername failed with the following error message : The WinRM client cannot process the request because the server name cannot be resolved l. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (servername:String) [], PSRemotingTransportException
+FullyQualifiedErrorId : ComputerNotFound, PSSessionStateBroken
我在所有服务器上都收到此错误,甚至在服务器上使用 Invoke-Command 上的脚本块运行其他命令(如 new-item 等)。 我不确定我错过了什么。有人可以帮我使用 Powershell 远程安装远程服务器上的文件夹中的所有 exe 和 msu 吗? 谢谢!
【问题讨论】:
-
$_是一个特殊值,仅在您的情况下有时才可用我相信您想要$sname -
@EBGreen 感谢您的回复。现在错误消失了,但我得到所有服务器的返回代码 9“Process Create failed with 9”。
-
错误代码 9 是找不到路径错误。
-
@EBGreen 是的,能够找到问题,它是“select-object FullName”,它返回“@{FullName=H:/InstallationFiles/Patch/filename.exe}”关于如何解决的任何想法解决这个问题?
-
Select-Object -ExpandProperty FullName
标签: powershell