Hello Experts,
I am having an issue exporting machine sids so I can properly identify that there are no duplicate sids within my environment and keep a archive of machines.
There is a sample of the code that I am playing with.
First, I enter in this cmdlet:
Get-ADComputer -Filter “*” | where {$_.Name -match “client”} | select SID | ft -HideTableHeader >>results1.txt
See results1.txt.
As you can see from results1.txt, there are white spaces all over the output. So I then decided to use trim the data by creating a custom variable.
$a = Get-ADComputer -Filter “*” | where {$_.Name -match “client”} | select SID | ft -HideTableHeaders | Out-String
$a.Trim() >>results2.txt
See results2.txt
As you can see in results2.txt, I successfully trimed the last value however, the first value still has some white space within the output.
I then proceed to run this output but now it merges all the data.
$b = $a.Trim()
$b -replace “\s”,“”
If anyone has any suggestions on what I can do, it would be greatly appreciated.
Thank you.