
我想重置 wsus 服務並刪除可選一台或多台主機(最多 200 台主機)上下載的更新。
我想 ping 主機並導出到一個文件:包含線上和離線結果的 excel。
***
下一個願望是當我輸入密碼時,密碼部分帶有星號。cls $User = Read-Host "Enter username" $Pass = Read-Host "Enter password" cls
4如果需要的話,最好將其複製psexec
到每個人的主機上。C:\temp
我建立了一個 bat 檔案來重置 WSUS 服務並刪除下載的更新。
clean_wsus.bat file:
net stop wuauserv
net stop bits
cd\
cd C:\Windows\SoftwareDistribution
del *.* /s /q
net start wuauserv
net start bits
wuauclt /resetauthorization /detectnow
這在一台主機上運作良好。
這是 powershell 腳本:
$input = Read-Host @"
Select Option
(1)Manually enter computer(s)
(2)Retrieve computer(s) from file
Option
"@
If ($input -eq 1){
$count = Read-Host "How many computers"
$Computers = 1..$count
$b=0;$c=1; ForEach ($Computer in $Computers) {$Computers[$b] = Read-Host "Computer" $c; $b++; $c++}
} ElseIF ($input-eq 2) {
$Computers = Read-Host "File"
$Computers = Get-Content $Computers
} Else {
write-host "Invalid Option"
Exit
}
cls
$User = Read-Host "Enter username"
$Pass = Read-Host "Enter password"
cls
$PSExec = "C:\Temp\PsExec.exe"
ForEach ($Computer in $Computers){
& $PSExec \\$Computer -u $User -p $Pass -h "C:\Temp\clean_wsus.bat"
}
這是我得到的錯誤:
PsExec v2.33 - Execute processes remotely
Copyright (C) 2001-2021 Mark Russinovich
Sysinternals - www.sysinternals.com
PsExec.exe : The handle is invalid.
At C:\Temp\WSUS\Script\WSUS Update.ps1:31 char:1
+ & $PSExec \\$Computer -u $User -p $Pass -h "C:\Temp\clean_wsus.bat"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (The handle is invalid.:String) [], RemoteExce
ption
+ FullyQualifiedErrorId : NativeCommandError
Logon failure: the user has not been granted the requested logon type at this computer.
Connecting to local system...
Connecting to local system...
Starting PSEXESVC service on local system...
Copying authentication key to NB***...
Connecting with PsExec service on NB***..
Starting C:\Temp\clean_wsus.bat on NB***....
Couldn't install PSEXESVC service:
PsExec could not start C:\Temp\clean_wsus.bat on NB***.: