Reputation: 2019
I have the following code,
Get-AdGroup -filter * | select Name, sAMAccountName | Foreach-Object{
New-Object PSObject -Property @{
oldAccount = $_.Name
newAccount = "c:0-.t|adfs-2|" + $_.sAMAccountName
}
} | Export-CSV "ADGroups.csv" -NoTypeInformation
This works as designed and everything comes out as it should but they do not comeout in the order I need. I believe they come out in alphabetical order so the newAccount is always first. How can I make newAccount the second column?
Upvotes: 0
Views: 83
Reputation: 9991
You could add a Select-Object prior to the export, that will define the order.
Get-AdGroup -filter * | select Name, sAMAccountName | Foreach-Object{
New-Object PSObject -Property @{
oldAccount = $_.Name
newAccount = "c:0-.t|adfs-2|" + $_.sAMAccountName
}
} | select oldAccount, newAccount | Export-CSV "ADGroups.csv" -NoTypeInformation
Upvotes: 1
Reputation: 1620
Well, you could write your own CSV
"`"oldAccount`",`"newAccount`"" | Out-File "ADGroups.csv"
Get-AdGroup -filter * | select Name, sAMAccountName | Foreach-Object{
"`"$_.Name`",c:0-.t|adfs-2|$_.sAMAccountName" | Out-File "ADGroups.csv" -append
}
Upvotes: 1