这是我的第一个问题,在PowerShell上我也很陌生,所以我希望一切正常。
我的问题如下:我想在多台计算机上卸载程序,检查注册表项是否已删除,然后安装该程序的新版本。
该设置位于与计算机位于同一域中的服务器上。
我希望我的脚本在计算机之间循环并为每台计算机从服务器执行安装程序。由于我是PowerShell的新手,所以我不知道该怎么做。我当时在考虑使用Copy-Item,但我不想真正移动设置,而只是将其从服务器执行到计算机上吗?任何想法如何做到这一点?
最好的祝福
您可以尝试以下方法。
请注意,需要显式提供凭据是臭名昭著的双跳问题的一种解决方法。
# The list of computers on which to run the setup program.
$remoteComputers = 'computer1', 'computer2' # ...
# The full UNC path of the setup program.
$setupExePath = '\\server\somepath\setup.exe'
# Obtain credentials that can be used on the
# remote computers to access the share on which
# the setup program is located.
$creds = Get-Credential
# Run the setup program on all remote computers.
Invoke-Command -ComputerName $remoteComputers {
# WORKAROUND FOR THE DOUBLE-HOP PROBLEM:
# Map the target network share as a dummy PS drive using the passed-through
# credentials.
# You may - but needn't - use this drive; the mere fact of having established
# a drive with valid credentials makes the network location accessible in the
# session, even with direct use of UNC paths.
$null = New-PSDrive -Credential $using:cred dummy -Root (Split-Path -Parent $using:$setupExePath) -PSProvider FileSystem
# Invoke the setup program from the UNC share.
& $using:$setupExePath
# ... do other things
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句