2

Have a CSV that has headers "SamName", "Email", "UPN"

Each record is how it shows in AD currently.

I am trying to add a 5th column with the ObjectGUID as follows:

$CsvFile = Import-Csv C:\test\file.csv
$CsvFile | ForEach-Object -Process { `
    $data1 = Get-ADUser -Identity $_."SamName" -Properties * | Select-Object ObjectGUID
    $_ | Add-Member -MemberType NoteProperty -Name UserGUID -Value $data1 -PassThru } `
    Export-CSV C:\test\file2.csv

When I open the CSV, the new column is called "UserGUID" as I had expected.

The GUID's that show are like this:

@{ObjectGUID=2e9dddec-f95d-4c67-a374-b102ce7e6f74}

Why don't they just show 2e9dddec-f95d-4c67-a374-b102ce7e6f74 in the column instead?

A second question, is why at the top of the Csv do I see #TYPE System.Management.Automation.PSCustomObject ?

1 Answer 1

2

Two guesses to answer your questions...

Select-Object -ExpandProperty ObjectGUID

and

Export-CSV C:\test\file2.csv -NoTypeInformation

See Get-Help for various commands to see all the options.

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

1 Comment

Worked a charm! Thank you!

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.