I am querying list of domain joined computers using powershell as below:
dsquery.exe computer > "C:\testfolder\host.txt"
Output is working as expected, but it is as shown below:
"CN=WIN-20CCF3DC8D,OU=Domain Controllers,DC=hosting,DC=xyz,DC=com"
"CN=WIN-20XYS8CM7D,OU=Computers,DC=hosting,DC=xyz,DC=com"
Here I need the following to do.
Either:
I need to edit this file (using powershell): remove all " character, remove all entries where OU not equal to Computers.
Or
I need to get contents of CN to a string but without ".
Have tried using
$contents = Get-Content C:\testfolder\host.txt | Foreach-Object {$_ -replace '"', ""}
but not seems to be working. Can someone please help me on this.?
This should work :
Then
echo $contents
gives :This returns only lines containing
OU=Computers
and removes double quotes from those lines.