0

beeing a newbie in programming and powershell scripting, i hope that you can help me out with the following problem.

Currently iam working on a script to make it easy to assign a telephone-number to a AD-User. The idea is just to enter the name of the user and the script searches for the UPN and assigns the correct phonennumber to use in teams (pbx) . In the end the script should display the status of the team user to check if the number was configured correctly via "Get-CsOnlineUser -Identity $aduserupn"

The Script looks like this:

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

The problem is, that this Get-CsOnlineUser cmdlet used with the script does not show me any result. When i directly enter it into powershell, it works and shows me the result:


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

All others csOnline-cmdlets are working fine. Do you see whats wrong here?

Thank you very much!

Panagiotis Kanavos
134k16 gold badges210 silver badges270 bronze badges
asked Apr 20, 2021 at 14:02
2
  • DON'T use the script tag. Every SO question is about scripts one way or another. It's no better than adding code as a tag. That tag is just noise, it was deleted in the past and will be deleted very soon again. Commented Apr 20, 2021 at 15:46
  • Allright, sorry :) Commented Apr 21, 2021 at 7:49

1 Answer 1

0

Copying answer from @panagiotis comments for better understanding.

DON'T use the script tag. Every SO question is about scripts one way or another. It's no better than adding code as a tag. That tag is just noise, it was deleted in the past and will be deleted very soon again.

answered Apr 21, 2021 at 12:24
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.