powershell - Powershell 将所有 exe 和 msu 安装在远程服务器上的文件夹中
问题描述
我能够使用此解决方案将所有补丁和 exe 从一台服务器复制到服务器列表 现在我正在尝试将所有补丁和 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 安装在远程服务器上的文件夹中吗?谢谢!
解决方案
Is the MSU file that you are trying to install? if yes, you need to decompress the file.. will generate the cab file I guess... and than you can make it.
$newproc=([WMICLASS]”\\$_\root\cimv2:win32_Process”).Create(“DISM.exe /Online /Add-Package /PackagePath:$installpath ”)
推荐阅读
- masstransit - MassTransit RequestClient 超时处理
- javascript - 无法识别对象属性:Uncaught ReferenceError: fat is not defined
- jsonata - 如何在 Jsonata 中以 $match 模式传递动态字符串?
- waze - 是否可以离线使用 Waze 或使用他们的路由算法进行开发?
- spring-mvc - AsyncRestTemplate + 协程
- azure-maps - 是否有用于地理定位的打字稿或 javascript api - 在 Azure Maps npm 模块 azure-maps-rest 中获取 IP 到位置预览功能
- python - 无法选择正确的 Cookie 以使用 python 代码登录
- python - pythonscript没有用pdflatex编译
- angular - 如何根据屏幕上剩余的可用空间向数组添加更多项目
- python - 在子类 QtCore.QAbstractItemModel 上使用 QSortFilterProxyModel 时,PyQt5 Treeview 不需要扩展索引