微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MS Teams - Powershell / 脚本 - Get-CsOnlineUser cmdlet 提供错误的输出 / PBX-Telephony

如何解决MS Teams - Powershell / 脚本 - Get-CsOnlineUser cmdlet 提供错误的输出 / PBX-Telephony

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

目前我正在编写一个脚本,以便轻松地为 AD 用户分配电话号码。这个想法只是输入用户的姓名,脚本搜索 UPN 并分配正确的电话号码以在团队 (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 评论中的答案以便更好地理解。

不要使用脚本标签。每个 SO 问题都以某种方式与脚本有关。这并不比将代码添加为标签更好。那个标签只是噪音,它过去被删除了,很快就会再次删除。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?