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

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Jeff Taylor Jeff Taylor 5 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #38489
    Profile photo of Jeff Taylor
    Jeff Taylor
    Participant

    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

    #38494
    Profile photo of Jeff Taylor
    Jeff Taylor
    Participant

    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

    #38497
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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
        }
    }
    
    #38528
    Profile photo of Jeff Taylor
    Jeff Taylor
    Participant

    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 "[email protected]" 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:

    #38535
    Profile photo of Jeff Taylor
    Jeff Taylor
    Participant

    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

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.