I am fetching AD groups and trying to trim the end space and putting them in a text file. However, this works (Method 1):
$filepath = "A"
$domain = "B"
$ADnames = Get-ADGroup -Server $domain -Filter *| select SAMAccountName | out-file "$filepath\test.txt"
get-content "$filepath\test.txt" | foreach {$_.trimend()} | out-file ""$filepath\test1.txt""
But this doesn't (Method 2):
$filepath = "A"
$domain = "B"
$ADnames = Get-ADGroup -Server $domain -Filter *| select SAMAccountName | foreach-object {$_.trimend()} | out-file "$filepath\test.txt"
Can i not pipeline it directly ?
I do not want to create an additional file like i am doing in method 1.
| select -ExpandProperty SAMAccountName |.. | select-object SAMAccountNameoutputs roughly this structure: --------------[psobject]@{ "SAMAccountName" = "Group1" }- a psobject with a name and a value. The code.. | select-object -ExpandProperty SAMAccountNameoutputs just the content"Group1"as a string