Author Posts

June 9, 2013 at 10:58 am

We have an application that requires a unique number for each user to be entered into the user's 'Pager' field in AD.

I'm using Import-Csv to create all of the users, but can't find a away of populating each user's 'Pager' field using either New-ADUser or Set-ADUser.

Is this possible?

June 9, 2013 at 11:29 am

Not directly, no – the commands don't directly wire up that attribute. You will have to pass it in a hashtable to the -Properties parameter instead

June 9, 2013 at 12:32 pm

OK, before I posted, I tried something along the lines of:

@{l='pager';e={'Unique-header-from-spreadsheet'}}

You're right – it gave me a valid 'pager' value when I imported the CSV, but it didn't wire up to the AD account 'Pager' field.

I didn't find any -Properties parameter in either of the cmdlets I listed above, but I did find an -OtherAttributes parameter.

I've tried variations of:

@{pager = {$_.'unique-header-from-spreadsheet'}

I experimented moving the quotes around. The closest I got was a direct entry into the 'Pager' field, but it was just the phrase '$_.unique-header-from-spreadsheet' and not the relevant value.

I'm close – any chance of another clue?!

June 10, 2013 at 5:46 am

 All you need is a "simple" hash table; there's no need for a script block for the value field.

@{pager = $_.’unique-header-from-spreadsheet’}

June 10, 2013 at 5:58 am

Actually, the main problem is that the New-ADUser and Set-ADUser commands don't have a -Pager parameter. So you can't simply pipe in an object that has a Pager property – there's nowhere for it to go. You probably will need a different approach. Assuming a CSV file with a Name, samAccountName, and Pager column:

Import-CSV file.csv | ForEach { New-ADUser -Name $_.Name -SamAccountName $_.samAccountName -OtherAttributes @{'Pager'=$_.Pager} }

June 16, 2013 at 4:43 am

Thanks to you both. Got it working.

I think my way was too complicated. Don's was simpler than what I'd come up with so I copied his format.

Cheers.

July 15, 2013 at 10:32 am

OK, just to follow on from that, I've exported a list of users whose 'Pager' field is empty. I've done a vlookup against a master spreadsheet to get the correct pager numbers for each user and ended up with a 2-column CSV file (Headers are 'SamAccountName' and 'Pager')

You're right – 'Set-ADUser' doesn't have a 'Pager' parameter, and this time it doesn't have an '-OtherAttributes' parameter either.

Meh.

Thought I'd play with it before coming here asking for more hand-outs! Read the help for Set-ADUser and found the answer!

Import-CSV C:\user_pagers.csv | ForEach-Object {Set-ADUser $_.SamAccountName -Replace @{Pager=$_.Pager}}

Re-sult!

February 16, 2015 at 2:09 am

OK, just to follow on from that, I've exported a list of users whose 'Pager' field is empty. I've done a vlookup against a master spreadsheet to get the correct pager numbers for each user and ended up with a 2-column CSV file (Headers are 'SamAccountName' and 'Pager')

You're right – 'Set-ADUser' doesn't have a 'Pager' parameter, and this time it doesn't have an '-OtherAttributes' parameter either.

Meh.

Thought I'd play with it before coming here asking for more hand-outs! Read the help for Set-ADUser and found the answer!

Import-CSV C:\user_pagers.csv | ForEach-Object {Set-ADUser $_.SamAccountName -Replace @{Pager=$_.Pager}}

Re-sult!

For those who haven't tried this yet. I confirm it works.
Thanks for your answer!