Running a Batch File on All Computers

I am still new to PowerShell and do not get to use it a lot, but I found a task that I think makes sense to use it for. I have a program scheduled to update server-side soon, which will require all of our workstations to run a client installer to upgrade. I wrote a batch file to silently install the upgrade on the clients, but didn’t know the best way to push it out so I don’t have to literally go to every workstation to do the install.

I figured I can query AD to get a list of workstations and put them in a txt file, then do something like:

$computerList = Get-Content 'C:pathtotxt' ForEach ($computer in $computerList) { $testingConnection = Test-Connection -ComputerName $computer -Count 1 -Quiet If (testingConnection -eq 'True') { Write-Host "$computer is online." -ForegroundColor Green Invoke-Command -FilePath '\serverfolderscript.bat' } Else { Write-Host "$computer is OFFLINE!" -ForegroundColor Red -BackgroundColor Yellow } } 

Like I said, I am fairly inexperienced. Does this look like it would accomplish what I am wanting? I was thinking testing the connection first would save time from not trying to install on computers that are offline.

submitted by /u/oldschoolsensei
[link] [comments]

Leave a Reply