I have the following PowerShell script:
Import-Module ActiveDirectory
# Find all accounts with a Department
# Copy that value into Description
Get-ADUser -filter * -Properties telephoneNumber, otherTelephone, facsimileTelephoneNumber, otherFacsimileTelephoneNumber, mobile, otherMobile |
Select-Object * |
ForEach-Object {Set-ADObject -Identity $_.DistinguishedName `
-Replace @{otherTelephone=$($_.telephoneNumber);otherFacsimileTelephoneNumber=$($_.facsimileTelephoneNumber);otherMobile=$($_.mobile)}}
The problem is, that some users don't have a mobile phone number or facsimile Number. For these users I receive the following error message:
Set-ADObject : Der Parameter "Replace" kann nicht an das Ziel gebunden werden. Ausnahme beim Festlegen von "Replace": " Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt." Bei C:\Scripts\Set_AD_Phone.ps1:8 Zeichen:9 + -Replace <<<< @{otherTelephone=$($.telephoneNumber);otherFacsimileTelephoneNumber=$($.facsimileTelephoneNumber);ot herMobile=$($_.mobile)}} + CategoryInfo : WriteError: (:) [Set-ADObject], ParameterBindingException + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.ActiveDirectory.Management.Commands.SetADObject
I cannot see any error at the script. does anyone has an idea?