简体   繁体   中英

powershell script to connect to multiple computers and execute some wsus related commands

I'm trying to set up a powershell script to automatically connect to multiple client computers that didn't send a report to wsus, and execute some wsus related commands.

I figured out how to get the list of computer that don't send the report anymore. This is the command I used:

$ClientsList = Get-WsusComputer -ComputerTargetGroups CLIENT
    -ToLastReportedStatusTime 01/01/2020 | Select-Object FullDomainName

But now that I have the clients' list, my problem is that I don't know what commands to use to be able to automatically start an "Enter-PSSession" to every client.

Of course I could manually provide every clients' name to connect to, but I would like to manage this automatically starting from the list I got.

Thank you in advance for any help you will provide.

Have you tried it with invoke-command? This foreach connect to each client in you list and execute the code inside the ScriptBlock parameter.

ForEach ($Client in $ClientsList)
{
     Try
         {
             Invoke-Command -ComputerName $Client -ScriptBlock {YOUR CODE} -ErrorAction Stop
         }
     Catch
         {
             Add-Content Unavailable-Clients.txt $Client
         }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM