i imported from file IDs and base on this ID i am trying to get information from AD…and insert this information as columns in original file…this is the code:
$import = Import-Csv C:Tempcoputerstatus.csv
Foreach ($item in $import) {
$user = Get-ADUSer -Identity $item.ID
#$item = New-Object psobject
$item | Add-Member -MemberType NoteProperty -Name "office" -Value $user.office
$item | Add-Member -MemberType NoteProperty -Name "title" -Value $user.title
$item | Add-Member -MemberType NoteProperty -Name "displayname" -Value $user.name
} #foreach
$import | Export-Csv C:tempmy.csv
but it is no working very well..i success to insert the headers but the value is empty(,,,)
i would like to same help
thanks
3
Answers
Get-ADUser and other active directory cmdlets operate a little funny. When you ask for an ADUser object Get-ADuser only returns a small subset of the properties available. Office and title are not available in this default set. To get what you want add the -Property parameter to Get-ADUser and ask for title and office in addition to the defaults it normally returns
if you want to retrieve all possible properties use an asterisk
It actually sounds like you may not be getting any user object back from Get-ADUser. Have a look at what is in the ID column in your csv files. Manually check what you are getting back from the import-csv command
Make sure that you have an ID property in that list. If so go ahead and check if your objects have ID values that you expect
If everything looks fine there try taking one of those IDs and manually running the Get-ADuser command replacing $item.ID with one of the actual IDs.
Do you get anything back?
Two ways…you can use splatting to dump all of the properties into the CSV for each like this…
Or you can select specific properties that you care about, like this…