I am new to powershell. Some help please.
I am trying to get a list of hostname from an OU which contains only computer object, I would like to sort the rows of hostname and only output a smaller list of hostname which contains certain keywords (Sales_PC1, Sales_PC2 etc...) to a txt file.
$PCList = Get-ADComputer -SearchBase 'OU=MyComputerOU, dc=contoso, dc=co, dc=nz' -Filter '*' |Select -Expand Name
The above command returns all the computer objects that are sitting in the "MyComputerOU".
What PowerShell command should I use to extract data from the variable $PCList and output it to a txt file?
Your help would be much appreciated.