Link to home
Start Free TrialLog in
Avatar of ThinkPaper
ThinkPaperFlag for United States of America

asked on

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)
Avatar of footech
footech
Flag of United States of America image

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

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

@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....
Yes.. some MS KB's have incorrect information..
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.
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
Avatar of ThinkPaper

ASKER

@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

ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!! =)