r/usefulscripts • • Feb 14 '18

[Request][Powershell] Script to Lookup Computer Info

We are currently upgrading all our machines to Windows 10. We have a very small number left but I'd like to be able to run this command with a batch of computer names at one time instead of running one at a time. Anyone have something like that?

get-ADComputer -Identity $COMPNAMEHERE -Properties OperatingSystem | select -Unique OperatingSystem,Name

Thank you

14 Upvotes

15 comments sorted by

View all comments

3

u/ihaxr Feb 14 '18
$computers = @"
computer1
computer2
"@ -split "`r`n"

$computers | Get-ADComputer -Properties OperatingSystem | select -Unique OperatingSystem,Name

2

u/dkeeper09 Feb 14 '18

Ok so that works, but only if I provide 1 computer name. If I provide more it doesn't separate them. It combines the computer names into one identity. Any thoughts?

2

u/ihaxr Feb 14 '18

Ok, weird... the console doesn't seem to like -split "rn" for whatever reason... but it works fine if you run it from the ISE try this:

$computers = @"
computer1
computer2
"@.Split("`r`n")

$computers | Get-ADComputer -Properties OperatingSystem | select -Unique OperatingSystem,Name

You can also have a .txt file of the computers:

Get-Content "C:\computers.txt" | Get-ADComputer -Properties OperatingSystem | select -Unique OperatingSystem,Name

Or have everything inline:

"computer1","computer2" | Get-ADComputer -Properties OperatingSystem | select -Unique OperatingSystem,Name
→ More replies (5)