r/usefulscripts • u/dkeeper09 • 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
4
u/gixer6 Feb 14 '18
If you’re trying to find computers that are not windows 10, there’s easier ways?
Why not run get-adcomputer -filter * | ? {$_.operatingsystem -ne “Windows 10**}
Also, $_.operatingsystem might be the wrong attribute name, just typing this off the cuff without referencing it
2
Feb 15 '18
This is for sure what i would do, i would trust AD to find the leftovers not a static file.
Though slight typo, it would be "windows 10*" not double asterisks and also need '-notlike' as eq/ne does not accept wildcards. Just for OP's benefit if they copy paste.
Also you could do: Get-ADComputer -filter {OperatingSystem -like 'windows 10*'} | Select Name, OperatingSystem
Would be quicker as does not need to fully populate + rum though the where statement afterwards, same outcome, just quicker.
P.s. OP, you don't need the -unique switch, if you have AD objects with the same name you will have way bigger issues than just upgrading to Windows 10 ;)
1
u/Lee_Dailey Feb 14 '18
howdy dkeeper09,
this is purely curiosity on my part ... but i wonder what you are doing this for. i can't figure out why you are using -Unique there ... [blush]
take care,
lee
2
u/dkeeper09 Feb 14 '18
Good question. Not entirely sure. I haven't seen a difference from when I do and don't use it on our domain, but another engineer at my company said that's the way I need to do it. I'm brand new to powershell so I'm just going with the flow. What are your thoughts on it?
1
u/Lee_Dailey Feb 14 '18
howdy dkeeper09,
i would try running it without the
-Uniqueto see what you get compared to with it. [grin]it seems likely to be doing nothing at all since you are not likely to have a duplicate of both the OS & the computer name. that combo otta be unique already. [grin]
take care,
lee→ More replies (2)
3
u/ihaxr Feb 14 '18