Author Posts

May 2, 2016 at 12:50 pm

I attempting a script that will get-content from a list of users and then user set-ADUser cmdlet to take the value from their respective mail property and set their msRTCSIP-PrimaryUserAddress property to it.

$C = Get-Credential
$Users = Get-Content C:\scripts\users.txt

ForEach ($User in $Users)
{
$ADUser = Get-ADUser $User -Properties msRTCSIP-PrimaryUserAddress
Set-ADUser $ADUser -EmailAddress "need an array value here I think" -Credential $C
}

I appreciate some help here.

thank you

May 2, 2016 at 3:19 pm

This seems to work to for one offs but not sure how to do en masse for multiple users:

$newsip = "sip:$($user.mail)"
Set-ADUser $user -replace @{'msRTCSIP-PrimaryUserAddress' = $newsip } -Credential $C

May 2, 2016 at 4:29 pm

This should get you close. Not tested. Note there is a -WhatIf switch that will need to be removed before it will actually make changes.

$creds = Get-Credential
$users = Get-Content C:\scripts\users.txt

foreach ($user in $users){
    $adUser = Get-ADUser $User -Properties msRTCSIP-PrimaryUserAddress
    if ($adUser) {
        $newSIP = "sip:$($user.mail)"
        try {
            Set-ADUser $adUser -replace @{ 'msRTCSIP-PrimaryUserAddress' = $newsip } -Credential $creds -ErrorAction Stop -WhatIf
        }
        catch {
            "Failed setting property for {0}. {1}" -f $user, $_.Exception.Message
        }
    }
    else {
        "User not found {0}" -f $user
    }
}

May 3, 2016 at 10:15 am

Thanks Rob...

For some reason, the resultant msRTCSIP-PrimaryUserAddress property only ends up with:

"sip:"

....and no value after that.

I've confirmed my User does have a value "user@mail.com" in it's mail attribute but it doesn't replace the value in msRTCSIP-PrimaryUserAddress

I've also confirmed the contents of the variable $newsip:

PS C:\> $newsip
sip:

May 3, 2016 at 11:00 am

Found the error with a friends help:

$creds = Get-Credential
$users = Get-Content C:\scripts\users.txt

foreach ($user in $users){
$adUser = Get-ADUser $User -Properties mail
if ($adUser) {
$newSIP = "sip:"+($adUser.mail)
try {
Set-ADUser $adUser -replace @{ 'msRTCSIP-PrimaryUserAddress' = $newsip } -Credential $creds -ErrorAction Stop
}
catch {
"Failed setting property for {0}. {1}" -f $user, $_.Exception.Message
}
}
else {
"User not found {0}" -f $user
}
}

Thanks again Rob