How to Filter Get-ADComputer by Operating System in PowerShell?

0
0
Asked By TechieWizard42 On

I'm working with PowerShell and have a command that retrieves information about computers using Get-ADComputer. However, I need help filtering the results to only include computers with a specific Operating System, or to exclude certain Operating Systems while still returning all other properties. The current command I'm using is:

Get-ADComputer -Filter * -Properties OperatingSystem, Created,IPv4Address, Description | Select-Object Name, OperatingSystem, Created, Description | Export-CSV -Path "C:UsersMNyUsrProfileNameDesktopAllComputers.csv" -NoTypeInformation

I'd like to modify this so I can filter based on the Operating System. Also, I've noticed that 'ADComputer' and 'Get-ADComputer' seem to return the same results. Is one just an alias for the other, or should I prefer one over the other? Thanks for the help!

5 Answers

Answered By PowerShellPro On

For filtering out a specific Operating System, try using this command:

Get-ADComputer -Filter * -Properties OperatingSystem, Created,IPv4Address, Description | Where-Object {$_.OperatingSystem -ne 'Windows Server 2016 Standard'} | Select-Object Name, OperatingSystem, Created, Description | Export-CSV -Path "C:UsersMNyUsrProfileNameDesktopAllComputers.csv" -NoTypeInformation. This will exclude any computer with that OS while still giving you all the other details.

Answered By SyntaxGuru On

And just to clarify your question, PowerShell creates aliases for Get-* commands. For instance, using 'ADUser -Filter *' works the same as 'Get-ADUser -Filter *'. So it's really just about personal preference, but 'Get-*' is more explicit.

Answered By CodeNinja99 On

You might want to check out the LDAP filter option as well. It can be more powerful and easier to handle in certain cases. It's worth exploring different filter syntheses to see what works best for your needs.

Answered By ScripterSally On

To filter based on the Operating System, you can use the command with a specific filter like this:

Get-ADComputer -Properties OperatingSystem -Filter {OperatingSystem -notlike "*2016*" }

This way, you can exclude computers running Windows Server 2016. Using -Filter is generally faster than using Where-Object.

Answered By HelpfulHarry On

If you’re looking to filter based on a specific Operating System, try adjusting your command to something like this:

Get-ADComputer -Filter * -Properties OperatingSystem, Created,IPv4Address, Description | Where-Object {$_.OperatingSystem -ne 'Windows Server 2016 Standard'} | Select-Object Name, OperatingSystem, Created, Description | Export-CSV -Path "C:UsersMNyUsrProfileNameDesktopAllComputers.csv" -NoTypeInformation.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.