Hi All,
I have once script to install patch on remote server that i try files copied on destation path but not able to install the patch on server. But i want to install few patches multiple remote server i have 2012 server, 2016, 2019 some server have 3 or 4 patches need to install some server have single patch need to install how can i install that server operating system wise or patch wise please guide me powershell script experts.
I want output servername patch KBArticel installation status successfull or failed in csv file.
$servers = Get-Content -Path "C:\Temp\InstallPatch\Servers.txt"
$source = "\\server\d$\patch\dec2021\2012 Server Patch"
$dest = "c$\Temp\
$testpath = "\\server\d$\patch\dec2021\2012 Server Patch\Windows8.1-kb5008263-x64_6d9eb2beed6c47dcc3957105718fc061b3b80.msu"
foreach ($server in $server) {
if (Test-Connection -Computername $servers -quiet) {
Copy-Item $Source -Destination \\$Server\$dest -Recurse -Force
if (Test-Path -Path$testPath) {
Invoke-Command -ComputerName $Server -ScriptBlock {Powershell.exe C:\Temp\Install\Windows8.1-kb5008263-x64_6d9eb2beed6c47dcc3957105718fc061b3b80.msu /sAll /msu /norestart AllUSERS=1 EULA_ACCEPT=YES
}
Write-Host "Installation Successfull on $Server" -ForegroundColor Green
}
} else {
Write-Host "$server is not online, Unable to install Patch, Patch Failed" -ForegroundColor Red
}
}
$Results | Out-File "C:\Temp\InstallPatch\PatchStatus.csv"