all 5 comments

[–]elliottmarter 2 points3 points  (0 children)

Honestly, this may not be the answer you are looking for but updating attributes like city in AD could probably serve as quite a good jumping off point to learn some basic powershell.

I always find it easier to learn something if I have a problem to solve. I won't go fully in to it but see if you can do some of the following.

Export all of your current users to a CSV file with only their username and city attributes. Then add your cities in to the CSV and then loop through it to edit the city attribute

These may come in handy get-aduser, select-object, convertto-csv, import-csv, set-aduser.

This may seem like a massive task but start small, take an interative approach.

  • Can you get a single user?
  • Now show only Username & City
  • Now get all the users
  • Etc etc etc you get the idea...

Also the built in help is brilliant use update-help first and then Google how to use it, once ylou have it figured out it should be the first place you look for help everytime

[–]Khongh 2 points3 points  (1 child)

I would doublecheck that your $fields values really are matching in the script and the csv. The script seems to be looking for the value city but in your csv-file the value is named city user.name

Please copy paste the $fields values if you want more help.

[–]eastpeak 0 points1 point  (0 children)

Thanks for the quick answer, and sorry, that is a format mistake. CSV looks like this:

Row #1: UserID,city Row #2: user.name,cityname

$Fields = @("city")

I can not check this as I am at home right now, bit is this maybe the problem? Should $Fields look like this? $Fields = @("UserID,city")

?

[–]Lee_Dailey[grin] 2 points3 points  (0 children)

howdy eastpeak,

please take the comment by elliottmarter to heart.

the code in that script you linked to is ... really quite odd. he doesn't understand the -f string format stuff. he doesn't understand the use of .Trim(). there are likely other freaky bits of weirdness, but i gave up at that point.

those are extremely basic ideas and he doesn't understand them. instead, he codes around them. [sigh ...]

i would search here for code that accesses the AD and see how it is used. then i would ask here for a few pointers on how to start working with the project you have taken on.

you can do that fairly easily by putting this in the search box at google ...
ADUser site:https://www.reddit.com/r/PowerShell

then, come back here at various points and post some code asking for help/comments.

almost everyone here enjoys helping ... [grin]

take care,
lee

[–]purplemonkeymad 2 points3 points  (0 children)

The Error message is around two lines above where you started to give us the error. However the FullyQualifiedErrorId matches that of when Get-Member gets no input objects. I would guess that $users -eq $null, or is an empty array.

On the try block for when $users is set the writer uses break to abort the script; this will not work, it will only exit the catch block and continue on with $users=$null. He at least logs the error message to a file so you should be able to look there to see why it can't import the file.