Score:1

Get all computers running specific Windows OS

ci flag

I'm currently in the process of upgrading all Windows 2012R2 and 2016 servers to 2019. I would like to run a Powershell cmdlet that will get all the computers on the domain that are powered on, and running these operating systems, as well as their hostnames and ip addresses. I have used Get-Computer in the past and got a long list of servers that had been turned off already, may have been using the wrong parameters, however would like something a bit cleaner and specific.

Davidw avatar
in flag
Run Get-Computer, store it in a variable, then send that in a foreach loop to test-connection to each computer. This will narrow it down to the systems that respond.
Score:3
us flag

Here's an example command for building a list of online computers matching a specific filter:

Get-AdComputer -Filter {OperatingSystem -like 'Windows Server*' -and DNSHostName -like '*' -and Enabled -eq $true} -SearchBase "OU=Servers,DC=Contoso,DC=com" -Properties operatingSystem | Sort-Object DNSHostName | ForEach-Object { if(Test-Connection -ComputerName $_.DNSHostName -Count 1 -Quiet){$Computers += @($_.DNSHostName);Write-Output "$($_.DNSHostName) is available and added to the array"} else {Write-Warning "$($_.DNSHostName) is unreachable"}}

You can then use the resulting $Computers array to run additional commands against those computers:

Invoke-Command -ComputerName $Computers -ScriptBlock {Get-Service -Name Spooler | Select-Object DisplayName,Name,StartType,Status -ErrorAction SilentlyContinue} | Format-Table PSComputerName,DisplayName,Name,StartType,Status
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.