0

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use Select-Object to pick the properties you want:

$result | sort-object SamAccountName | Select-Object SamAccountName, Group |  Export-CSV $FilePath

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.