Powershell - update PhysicalDeliveryOfficeName or Physical-Office-Delivery-Location

Experts - Need some help figuring this out.

We have a COTS product which is basically a webpage users can go to update their user info. The problem we have run into is that for Room/Office number, the website updates the "roomNumber" attribute. Unfortunately this is NOT the attribute that Outlook uses to reference Office location. Instead, Outlook seems to reference "physicalDeliveryOfficeName".

So since we already had hundreds of folks populate their information, I want to run a powershell command to update the "physicalDeliveryOfficeName" to equal "roomNumber".

I am trying to run the commands but it is not working. I assume it is because it is the wrong type?? (As if it's not a one-value string??)

This works to query roomNumber and physicalDeliveryOfficeName
get-aduser -LDAPfilter '(roomNumber=*)' -Properties *| select samAccountName, roomNumber, physicalDeliveryOfficeName

Open in new window


But when I attempt to set the value for physicalDeliveryOfficeName, it fails saying its not a valid:

Get-ADUser -LDAPFilter '(roomNumber=*)' -Properties roomNumber, Physical-Office-Delivery-Location | ForEach-Object {Set-ADObject -Identity $_.DistinguishedName -Replace @{Physical-Office-Delivery-Location=$($_.roomNumber)}}

Open in new window


Here's the errors I get:

PS C:\Windows\system32> get-aduser -identity "testuser" -Properties * | set-aduser "testuser" -physicalDeliveryOfficeName "1400TEST"
Set-ADUser : A parameter cannot be found that matches parameter name 'physicalDeliveryOfficeName'.
At line:1 char:94
+ get-aduser -identity "testuser" -Properties * | set-aduser "testuser" -physicalDeliveryOfficeName <<<<  "1400TEST"
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser

PS C:\Windows\system32> get-aduser -identity "testuser" -Properties * | set-aduser "testuser" -physical-Delivery-Office-Location "1400TEST"
Set-ADUser : A parameter cannot be found that matches parameter name 'physical-Delivery-Office-Location'.
At line:1 char:101
+ get-aduser -identity "testuser" -Properties * | set-aduser "testuser" -physical-Delivery-Office-Location <<<<  "1400TEST"
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser

Open in new window


(I used this: http://blogs.technet.com/b/ashleymcglone/archive/2012/07/23/how-to-copy-user-attributes-to-another-field-with-powershell.aspx as reference)
LVL 16
ThinkPaperIT ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
The attribute is PhysicalDeliveryOfficeName, you had PhysicalDeliveryOfficeLocation.
Get-ADUser -LDAPFilter '(roomNumber=*)' -Properties roomNumber | ForEach-Object {Set-ADObject -Identity $_.DistinguishedName -Replace @{PhysicalDeliveryOfficeName = $_.roomNumber}}

Open in new window

0
SubsunCommented:
physicalDeliveryOfficeName is the LDAP display name of Property Office... So
Set-ADUser -Identity $_.DistinguishedName -Office $_.roomNumber should also work..

Get-ADUser -LDAPFilter '(roomNumber=*)' -Properties roomNumber | % {Set-ADUser -Identity $_.DistinguishedName -Office $_.roomNumber}

Open in new window

0
footechCommented:
@Subsun - I thought they were the same, but when I checked the help for Set-ADUser to verify it said that the ldapdisplayname for -Office was "office", so I assumed I remembered incorrectly.  Just ran through an actual test and you're right.  Stupid documentation....
0
Do You Have a Trusted Wireless Environment?

A Trusted Wireless Environment is a framework for building a complete Wi-Fi network that is fast, easy to manage, and secure.

SubsunCommented:
Yes.. some MS KB's have incorrect information..
0
footechCommented:
I'm actually more tolerant of errors in online documentation than I am for built-in help, but I suppose for PS 3.0 they're all from the same source with the dynamic help.
0
SubsunCommented:
Only thing I remember is, PS3 has a updatable Help. If you need the online help then you need to use the -online switch.. or use the Update-Help or Save-Help cmdlets to update the local help files..

Get-Help <cmdlet-name> -Online
0
ThinkPaperIT ConsultantAuthor Commented:
@subsun:
I attempted to run using the "Office" attribute:

Get-ADUser -LDAPFilter '(roomNumber=*)' -Properties roomNumber | % {Set-ADUser -Identity $_.DistinguishedName -Office $_.roomNumber}

Open in new window


and got these errors:


Set-ADUser : Cannot convert 'Microsoft.ActiveDirectory.Management.ADPropertyValueCollection' to the type 'System.String' required by parameter 'Office'. Specified method is n
ot supported.
At line:1 char:118
+ Get-ADUser -LDAPFilter '(roomNumber=*)' -Properties roomNumber | % {Set-ADUser -Identity $_.DistinguishedName -Office <<<<  $_.roomNumber}
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.Management.Commands.SetADUser

If I try physicaldeliveryofficename, I get this:

Get-ADUser -LDAPFilter '(roomNumber=*)' -Properties roomNumber | % {Set-ADUser -Identity $_.DistinguishedName -PhysicalDeliveryOfficeName $_.roomNumber}

Open in new window


Set-ADUser : A parameter cannot be found that matches parameter name 'PhysicalDeliveryOfficeName'.
At line:1 char:138
+ Get-ADUser -LDAPFilter '(roomNumber=*)' -Properties roomNumber | % {Set-ADUser -Identity $_.DistinguishedName -PhysicalDeliveryOfficeName <<<<  $_.roomNumber}
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser
I am wondering if it is because roomNumber is a different type vs physicaldeliveryofficename?

When I run this I get no errors. But the problem is that the Office is STILL EMPTY. It does not update the field. =( What am I missing? Did it work for you guys?

Get-ADUser -LDAPFilter '(roomNumber=*)' -Properties roomNumber | ForEach-Object {Set-ADObject -Identity $_.DistinguishedName -Replace @{PhysicalDeliveryOfficeName = $_.roomNumber}}

Open in new window

0
SubsunCommented:
Change $_.roomNumber to $_.roomNumber[0] and see..

Get-ADUser -LDAPFilter '(roomNumber=*)' -Properties roomNumber | % {Set-ADUser -Identity $_.DistinguishedName -Office $_.roomNumber[0]}  

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
footechCommented:
Using the -Office parameter is probably a better fit in this case.  Using -replace with the attribute only works if the attribute to be updated already has a value.  We could use -add instead of -replace if the attribute is not currently set.  The -Office parameter doesn't care if the attribute is currently set or not.

The next issue is with the conversion.  Is there only one value in the roomNumber attribute?  If so, Subsun's method will work.  If there's multiple values and we need to include them all, then we can use a -join or pipe to Out-String (I've tested both methods).
0
ThinkPaperIT ConsultantAuthor Commented:
Subsun & footech, you guys rock! We only are using 1 value so no need to take into account multiple values. This was stumping me for a while. @__@ Thanks!! =)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.