locked
Skype for Business Powershell Script to Update Users Pool Location RRS feed

  • Question

  • When I run the following script I am getting the errors below. Any ideas how to get it to work?

    Basically I want it to check a Skype for Business users homed front end pool and if it is not APACFEPool.domain.local to change it to APACFEPool.domain.local. If it is APACFEPool.domain.local I want it to set it to APACFEPool.domain.local.

    $groupmember = Get-ADGroupMember TG-CHANGESFBPOOL | Get-AdUser
    foreach ($member in $groupmember)
    {
    $aduser = Get-CsUserPoolInfo -Identity $member.UserPrincipalName | Where-Object {$_.PrimaryPoolFQDN -ne "EMEAFEPool.domain.local"}
    if($aduser -ne “APACFEPool.domain.local”())
    {
    Move-CsUser -identity $aduser.identity -Target APACFEPool.domain.local
    }
    }

    At line:4 char:46
    + if($aduser -ne "APACFEPool.domain.local"())
    +                                              ~
    Unexpected token '(' in expression or statement.
    At line:4 char:46
    + if($aduser -ne "APACFEPool.domain.local"())
    +                                              ~
    Missing closing ')' after expression in 'if' statement.
    At line:4 char:47
    + if($aduser -ne "APACFEPool.domain.local"())
    +                                               ~
    An expression was expected after '('.
    At line:2 char:1
    + {
    + ~
    Missing closing '}' in statement block.
    At line:4 char:48
    + if($aduser -ne "APACFEPool.domain.local"())
    +                                                ~
    Unexpected token ')' in expression or statement.
    At line:8 char:1
    + }
    + ~
    Unexpected token '}' in expression or statement.
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
       ception
        + FullyQualifiedErrorId : UnexpectedToken

    Wednesday, July 18, 2018 12:22 PM

Answers

  • Is this what you are trying to do?

    (Get-ADGroupMember TG-CHANGESFBPOOL).DistinguishedName | foreach {
        $csuser = Get-CsUser $_
        if (
            $csuser.HostingProvider -ne "sipfed.online.lync.com" -and
            ($csuser | Get-CsUserPoolInfo).PrimaryPoolFQDN -eq "EMEAFEPool.domain.local"
        ) {
            $csuser | Move-CsUser -Target APACFEPool.domain.local -Confirm:$False
        }
    }
    

    • Marked as answer by Blue_man2 Monday, July 23, 2018 9:53 PM
    Friday, July 20, 2018 6:35 AM

All replies

  • You could start by removing the extra pair of parentheses in your if statements. Also, please post code using the code posting tool.
    Wednesday, July 18, 2018 1:40 PM
  • So I am nearly there. Users who are home online in office365 produce an error, so I want to exclude them and not run the final part of the script for any users who have the property of sipfed.online.lync.com. If I run the below command it does not execute no errors either.

    $groupmember = Get-ADGroupMember TG-CHANGESFBPOOL | Get-AdUser
    foreach ($member in $groupmember)
    {
    $csuserpoolinfo = Get-CsUserPoolInfo -Identity $member.UserPrincipalName | Where-Object {$_.PrimaryPoolFQDN -eq "EMEAFEPool.domain.local"}
    $aduser = Get-CsUser -Identity $member.UserPrincipalName | Where-Object {$_.HostingProvider -ne "sipfed.online.lync.com"}
    if($csuserpoolinfo -ne “APACFEPool.domain.local” –and $aduser –ne “sipfed.online.lync.com)
    {
    Move-CsUser -identity $aduser.identity -Target APACFEPool.domain.local -Confirm:$False
    }
    }

    Thursday, July 19, 2018 8:49 PM
  • Is this what you are trying to do?

    (Get-ADGroupMember TG-CHANGESFBPOOL).DistinguishedName | foreach {
        $csuser = Get-CsUser $_
        if (
            $csuser.HostingProvider -ne "sipfed.online.lync.com" -and
            ($csuser | Get-CsUserPoolInfo).PrimaryPoolFQDN -eq "EMEAFEPool.domain.local"
        ) {
            $csuser | Move-CsUser -Target APACFEPool.domain.local -Confirm:$False
        }
    }
    

    • Marked as answer by Blue_man2 Monday, July 23, 2018 9:53 PM
    Friday, July 20, 2018 6:35 AM
  • Yes, that has worked thanks. Where was I going wrong?
    Monday, July 23, 2018 9:54 PM
  • You piped Get-ADGroupMember to Get-ADUser in order to get UserPrincipalName. I chose to use DistinguishedName from Get-ADGroupMember.

    You piped Get-CsUserPoolInfo and Get-CsUser to Where-Object. That's unnecessary when you are dealing with a single object. It looks like you thought you were saving only the PrimaryPoolFQDN in $csuserpoolinfo, but if that was your goal you would have to use Select-Object -Expand PrimaryPoolFQDN instead of Where-Object.

    Because $csuserpoolinfo and $aduser are objects with many properties you would have to specify which property to do comparison on. For example you would have to change from $csuserpoolinfo -ne "APACFEPool.domain.local" to $csuserpoolinfo.PrimaryPoolFQDN  -ne "APACFEPool.domain.local".

    Tuesday, July 24, 2018 5:51 AM