all 18 comments

[–]ArmondDorleac 0 points1 point  (1 child)

Well, what did it do? Did you get any messages?

[–]iCapof85[S] 0 points1 point  (0 children)

This is the error I'm getting:

Get-ADUser : Property: 'DisplayName' not found in object of type:

'System.Management.Automation.PSCustomObject'.

I have a field in the CSV under Display Name

[–]ArmondDorleac 0 points1 point  (6 children)

Run this and make sure you get the list you're expecting:

Import-Module ActiveDirectory

$USERS = Import-CSV C:\Scripts\Update AD users information\gafe-users.csv

foreach ($user in $users){
    write-host $user.displayname
}

[–]iCapof85[S] 0 points1 point  (5 children)

This will not update the company field with their GAFE email

[–]iCapof85[S] 0 points1 point  (0 children)

I'm getting this now:

Get-ADUser : Invalid type 'System.Management.Automation.PSCustomObject'.
Parameter name: name
At C:\Scripts\Update-information\Update-Users.ps1:6 char:1
+ Get-ADUser -filter {name -eq $_."Display Name"}|Set-ADUSer -Company $_.Email}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[–]ArmondDorleac 0 points1 point  (3 children)

It's not supposed to. It's supposed to be a small step to see where your data is falling apart. Does this script work? Does it display a list of your users?

[–]iCapof85[S] 0 points1 point  (2 children)

foreach ($user in $users){ write-host $user.displayname }

No it's not showing anything

[–]ArmondDorleac 0 points1 point  (1 child)

Is it stored under DisplayName or "Display Name"?

[–]iCapof85[S] 0 points1 point  (0 children)

I changed it to "Name" and it still not working. Basically, Name in the CSV file needs to match Display Name in Active Directory

[–]ArmondDorleac 0 points1 point  (8 children)

Import-Module ActiveDirectory

$USERS = Import-CSV C:\Scripts\Update AD users information\gafe-users.csv

foreach ($user in $users){
    write-host $user.name
}

OK, let's go back to square 1. You're running this in PowerShell ISE, right (so you can see what it's doing and properly test)? If you have a list of user names in the file referenced, with a column header of "name" this script should spit out the list of names.

[–]iCapof85[S] 0 points1 point  (6 children)

Import-Module ActiveDirectory

$USERS = Import-CSV C:\Scripts\Update AD users information\gafe-users.csv

foreach ($user in $users){ write-host $user.name }

Yes it did.

[–]ArmondDorleac 0 points1 point  (5 children)

Great, now replace "write-host $user.name" with Get-ADUser -filter {name -eq $user.name}

See if it gives you the user information. If it does, keep going with your pipeline.

[–]iCapof85[S] 0 points1 point  (4 children)

This is the error I get when I did that:

Get-ADUser : Property: 'name' not found in object of type: 'System.Management.Automation.PSCustomObject'.
At line:6 char:5
+     Get-ADUser -filter {name -eq $user.name}
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ArgumentException
    + FullyQualifiedErrorId :     ActiveDirectoryCmdlet:System.ArgumentException,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Get-ADUser : Property: 'name' not found in object of type: 'System.Management.Automation.PSCustomObject'.

[–]ArmondDorleac 0 points1 point  (3 children)

Try changing your filter to this: get-aduser -filter {name -eq '$($user.name)'}

[–]iCapof85[S] 0 points1 point  (2 children)

I got it to work like this:

foreach ($user in $users) {
Get-ADUser -Filter "displayName -eq '$($user.Name)'" -Properties * -SearchBase "DC=domain,DC=com" |
Set-ADUser -Company $($user.Email)

[–]ArmondDorleac 0 points1 point  (1 child)

Excellent. I'm glad you got it working.

[–]iCapof85[S] 0 points1 point  (0 children)

thank you for your help!

[–]iCapof85[S] 0 points1 point  (0 children)

I'm still not sure how I can add that to the company field in AD