谁能帮我创建/编辑这个 powershell 脚本

谁能帮我创建/编辑这个 powershell 脚本
  1. 我想重置 wsus 服务并删除可选一个或多个主机(最多 200 个主机)上下载的更新。

  2. 我想要 ping 主机并将在线和离线结果导出到文件:excel。

  3. ***下一个愿望是当我输入密码时,密码部分带有星号。

    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***.:

相关内容