Reputation: 322
I am exporting A users from AD. It's working fine , I only have issue in the export file.
Current Output
A000354 CN=ATX_PUTTY,OU=Personal,OU=abc,OU=xyz,DC=dd,DC=pp,DC=net
Desired Output
A000354 ATX_PUTTY
$FilePath = "c:/LocalData/A_Users.csv"
$OuDomain = "OU=Personal,OU=Personal,OU=abc,OU=xyz,DC=dd,DC=pp,DC=net"
$users = Get-QADUser -SamAccountName [A]* -searchRoot $OuDomain -SizeLimit 0 -DontUseDefaultIncludedProperties
$result = $users | % {
$SamAccountName = $_.SamAccountName
if ($lastDomain -eq $_.dn) {
$lastDomain = ""
} else {
$lastDomain = $_.dn
}
$_.MemberOf | % {
$user = New-Object -TypeName PsObject -Property @{
"Domain" = $lastDomain
"SamAccountName" = $SamAccountName
"Group" = $_
}
$user
}
}
$result | sort-object SamAccountName | Select-Object SamAccountName, Group | Export-CSV $FilePath -NoTypeInformation
Now I am getting .....Output like
A000354 CN=ATX_PUTTY,OU=Personal,OU=abc,OU=xyz,DC=dd,DC=pp,DC=net
I want to Output like below , I dont want CN= and ,OU=Personal,OU=abc,OU=xyz,DC=dd,DC=pp,DC=net
A000354 ATX_PUTTY
Thanks.
Upvotes: 0
Views: 1197
Reputation: 24091
Use Get-Help Export-CSV -detailed
to see that there is a -NoTypeInformation
switch that does just the thing you need:
-NoTypeInformation [] Omits the type information from the CSV file. By default, the first line of the CSV file contains "#TYPE " followed by the fully-qualified name of the type of the .NET Framework object.
Upvotes: 2
Reputation: 12613
You can use Select-Object
to pick the properties you want:
$result | sort-object SamAccountName | Select-Object SamAccountName, Group | Export-CSV $FilePath
Upvotes: 0