Four Ways to Get Computer Names to the -computerName Parameter

I'm teaching a class for  SAPIEN Technologies  in Chicago this week. Actually, everyone's doing a lab on WMI, watching me enter this. Don't you wish you were here? Anyway, we needed to look at various ways to feed computer names to any cmdlet that has a -computerName parameter. Here's what I cam up with:

Don Jones

October 26, 2010

1 Min Read
ITPro Today logo in a gray background | ITPro Today

I'm teaching a class forSAPIEN Technologies in Chicago this week. Actually, everyone's doing a lab on WMI, watching me enter this. Don't you wish you were here? Anyway, we needed to look at various ways to feed computer names to any cmdlet that has a -computerName parameter. Here's what I cam up with:

# get names from a file, one name per lineGet-WmiObject -class Win32_Whatever -computer (Get-Content names.txt) # get names from Active DirectoryImport-Module ActiveDirectoryGet-WmiObject -class Win32_Something -comp (    Get-ADComputer -filter * | Select-Object -expand name) # specify one computerGet-WmiObject -class Win32_This -computer SERVER-R2 # specify many computersGet-WmiObject -class Win32_That -computer WESTDC4,EASTDC5 # get names from a CSV file that has a "host" columnGet-WmiObject -class Win32_Those -computer (    Import-CSV computerlist.csv | Select-Object -expand host)
I used Get-WmiObject for all of the examples, but you can obviously use this with any cmdlet that supports -computerName. Enjoy!

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like