MS团队-Powershell/Scripting-Get-CsOnlineUser cmdlet提供错误的输出/PBX电话

MS团队-Powershell/Scripting-Get-CsOnlineUser cmdlet提供错误的输出/PBX电话,powershell,microsoft-teams,skype-for-business,Powershell,Microsoft Teams,Skype For Business,作为编程和powershell脚本的新手,我希望您能帮助我解决以下问题 目前,iam正在编写一个脚本,以便于为广告用户分配电话号码。这个想法就是输入用户的名字,然后脚本搜索UPN并分配正确的phonennumber以在团队(pbx)中使用。最后,脚本应显示团队用户的状态,以通过“Get-CsOnlineUser-Identity$aduserupn”检查号码是否正确配置 脚本如下所示: Write-Host "Teams Script V1.4" -ForegroundCo

作为编程和powershell脚本的新手,我希望您能帮助我解决以下问题

目前,iam正在编写一个脚本,以便于为广告用户分配电话号码。这个想法就是输入用户的名字,然后脚本搜索UPN并分配正确的phonennumber以在团队(pbx)中使用。最后,脚本应显示团队用户的状态,以通过“Get-CsOnlineUser-Identity$aduserupn”检查号码是否正确配置

脚本如下所示:

Write-Host  "Teams Script V1.4" -ForegroundColor Yellow -BackgroundColor DarkGreen


Connect-MicrosoftTeams
    
# Get user and store AD-Phonennumber

function step1 {
    $done = $False
    while (-not $done){    
        try
        {
            $aduser = $null
            $VoiceRoutingPolicy = 'Via-Provider-Policy'
            $decission = ''

            $user = Read-Host -Prompt 'Please enter the user.name'
            $aduser = Get-ADUser -Identity $user -Properties telephonenumber -ErrorAction Stop
            $extension = $aduser.telephonenumber -replace '\s',''
            $aduserupn = $aduser.UserPrincipalName
         
            Grant-CsOnlineVoiceRoutingPolicy -Identity $aduser.UserPrincipalName -PolicyName $VoiceRoutingPolicy -ErrorAction Stop
            Set-CsUser -Identity $aduser.UserPrincipalName -EnterpriseVoiceEnabled $true -HostedVoiceMail $false -OnPremLineURI tel:$extension -ErrorAction Stop
            write-host $aduser.UserPrincipalName
            Get-CsOnlineUser -Identity $aduserupn -ErrorAction Stop | select DisplayName, RegistrarPool, OnlineVoiceRoutingPolicy, LineURI, OnPremLineURI, EnterpriseVoiceEnabled, HostedVoicemail         
            write-host "Done - Please check status above" -ForegroundColor Yellow -BackgroundColor Green
            
            $decission = Read-Host -Prompt 'Do you want to activate another user? (y)es / (n)no'
            if ($decission -eq 'y'){
                
            } else {
                $done = $True
            }
        }
        catch
        {
            if ($aduser -eq $null) {
                Write-Host "The Username was not found, please try again!" -ForegroundColor Red -BackgroundColor DarkGreen
            }
        }
    }
}

step1

write-host "Done - Disconnecting Session." -ForegroundColor Yellow -BackgroundColor Green
get-pssession | remove-pssession

问题是,与脚本一起使用的Get-CsOnlineUser cmdlet没有显示任何结果。当我直接将其输入powershell时,它会工作并向我显示结果:


DisplayName              : Name, Name
RegistrarPool            : sippoolAM41E07.infra.lync.com
OnlineVoiceRoutingPolicy : Provider-Policy
LineURI                  : tel:+XXXXXXXXXXXXX
OnPremLineURI            : tel:+XXXXXXXXXXXXX
EnterpriseVoiceEnabled   : True
HostedVoiceMail          : False

所有其他csOnline cmdlet都工作正常。你知道这里出了什么问题吗


多谢各位

复制@panagiotis评论中的答案,以便更好地理解


不要使用脚本标记。每个问题都是关于脚本的。这并不比添加代码作为标记好多少。该标记只是噪音,它在过去已被删除,不久将再次被删除。

不要使用
脚本
标记。每个问题都是关于脚本的。这并不比添加
code
作为标记好多少。那个标签只是噪音,它以前被删除过,很快就会被删除。好吧,对不起:)