Query ADUsers in .csv, set-ADUser attrib with array property

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

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

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

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:

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