Powershell Selecting Certain Output

Viewed 50

Just wondering how I can extract a certain line/text of output from Powershell. I am trying to get the OU of the PC without having Active Directory module installed on the PC running the script.

The only way I can think of is GPResult /R then extract the output.

So far I have:

GPResult /r /SCOPE:COMPUTER | Select-String OU=

Which returns:

CN=PC-12345,OU=Test Devices,OU=Middle Layer,OU=Top Layer,OU=Equipment,DC=Test,DC=Lab

I need to select the OU=Test Devices, however every time I run the script the OU will be different so cannot search by the OU name itself.

0 Answers
Related