# This script calls on remote computers of the LAN "Search", "Install updates" and "Send instant Report" of updates to WSUS server. # On every computer must be enabled on firewall WMI, Remote administration of services and on registry LocalAccountTokenFilterPolicy=1. # WSUS server must be set on registry. # Script needs the same directory: # - program psexec (Mark Russinovich) # - list names of PC in "PcList.txt" (names of PC in 1 line separated by spaces). # http://vyuka.jihlavsko.cz/administrator/ # Jiri Hrodek 2018 $menu=@" 1 Search updates 2 Install updates 3 Send Report to WSUS 4 Chkdsk C: after reboot R Reboot O PowerOff Q Quit Select number or Q to quit "@ cls Write-Host "-------------------WHAT TO DO for computers below?-------------------" -ForegroundColor Cyan $column = (Get-Content PcList.txt) -split '\s+|\t+' Write-Host "Computers: "$column $r = Read-Host $menu Switch ($r) { "1" { Add-Content log-WU-StartInteractiveScan.log (Get-Date -Format g) foreach($line in $column) { .\psexec \\$line C:\Windows\System32\UsoClient.exe StartInteractiveScan Add-Content log-WU-StartInteractiveScan.log $line"`t errorlevel "$lastexitcode } } "2" { Add-Content log-WU-StartInstall.log (Get-Date -Format g) foreach($line in $column) { .\psexec \\$line C:\Windows\System32\UsoClient.exe StartInstall Add-Content log-WU-StartInstall.log $line"`t errorlevel "$lastexitcode } } "3" { Add-Content log-WU-Report-send.log (Get-Date -Format g) foreach($line in $column) { .\psexec \\$line C:\Windows\System32\UsoClient.exe StartInteractiveScan .\psexec \\$line wuauclt /reportnow Add-Content log-WU-Report-send.log $line"`t errorlevel "$lastexitcode } } "4" { Add-Content log-Chkdsk.log (Get-Date -Format g) foreach($line in $column) { .\psexec \\$line cmd /c "echo y.|chkdsk c: /f" Add-Content log-Chkdsk.log $line"`t errorlevel "$lastexitcode } } "R" { Add-Content log-Reboot.log (Get-Date -Format g) foreach($line in $column) { .\psexec \\$line C:\Windows\System32\shutdown.exe -r -t 00 Add-Content log-Reboot.log $line"`t errorlevel "$lastexitcode } } "O" { Add-Content log-PowerOff.log (Get-Date -Format g) foreach($line in $column) { .\psexec \\$line C:\Windows\System32\shutdown.exe -s -t 00 Add-Content log-PowerOff.log $line"`t errorlevel "$lastexitcode } } "Q" { Write-Host "Quitting" -ForegroundColor Green } default { Write-Host "End without action." -ForegroundColor Yellow } } #end switch