DownOL 软件仓库– 软件下载,字节世界与新知

用脚本为远程计算机安装指定的应用程序

发表于:2024-05-06 作者:创始人
编辑最后更新 2024年05月06日,计算机运维人员很多时候需要给多台计算机安装应用程序,如果一台台安装效率非常低,我们可以通过PowerShell脚本执行远程安装。脚本如下:执行脚本前,需要在客户机和管理机分别执行:Enable-PSR

计算机运维人员很多时候需要给多台计算机安装应用程序,如果一台台安装效率非常低,我们可以通过PowerShell脚本执行远程安装。

脚本如下:

执行脚本前,需要在客户机和管理机分别执行:Enable-PSRemoting ,开启powershell的远程管理。

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

$source="c:\install"

$dest="c$"

$testPath="c:\install\AcroRdr.exe"

foreach($computer in $computers){

if(test-Connection-Cn $computer-quiet){

Copy-Item $source -Destination \\$computer\$dest -Recurse -Force

if(Test-Path-Path $testPath){

Invoke-Command -ComputerName $computer -ScriptBlock{powershell.exe c:\install\AcroRdr.exe /sAll /msi /norestart ALLUSERS=1 EULA_ACCEPT=YES}

Write-Host -ForegroundColor Green " $computer 已安装成功"

}

}else{

Write-Host -ForegroundColor Red "$computer 设备不在线"

}

}

2022-05-09 12:51:25
0