通过PowerShell从远程计算机上的服务器执行卸载安装



这是我在这里的第一个问题,我对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 = '\serversomepathsetup.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
} 

最新更新