MS Teams-Powershell/Scripting-Get-CsOnlineUser cmdlet传递错误的输出



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

目前,我正在编写一个脚本,以便轻松地为AD用户分配电话号码。这个想法只是输入用户的名称,脚本搜索UPN并分配正确的电话号码以在团队中使用(pbx(。最后,脚本应该显示团队用户的状态,以检查数字是否通过"strong"配置正确;获取CsOnlineUser-标识$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评论中复制答案以更好地理解。

不要使用script标记。每个SO问题都是关于脚本的。这并不比添加代码作为标记更好。那个标签只是噪音,它在过去被删除了,很快就会再次被删除。

最新更新