Active Directory 'Pager' field

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?

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

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?!

 All you need is a “simple” hash table; there’s no need for a script block for the value field.
<pre class=“lang:ps decode:true”>@{pager = $_.’unique-header-from-spreadsheet’}

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} }

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.

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!

thickgit wrote:
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!