Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, March 27, 2018 3:33 PM
Hi all, pretty new to scripting and can't find anything that matches what I'm looking to do. I have a simple PowerShell command I run to enable users for voice in Skype for Business Online but the mandatory LocationID is just a random string of letters and numbers so there is no way to memorize them.
What I would like to do is have it prompt me with the option to choose based on the actual location name (New York, Chicago, etc.) but it will write the actual string, ex.: "3l29675a-14x0-42f5-jfd2-b624e112bf0"
The script has two Read-Host options first and then this would be the final parameter to set. We have around 15 locations to choose from but it's a really basic command so I didn't want anything too complicatedSo the script (so-far):
$Identity = Read-Host "Enter the username"
$TN = Read-Host "Enter TN in E.164"
*[This is where I want something that says $Chicago = *"3l29675a-14x0-42f5-jfd2-b624e112bf0", $NewYork = "3l29123a-14x0-42f5-jfd2-b624e987uh0" etc. and when the script is run I get presented to choose one of those sites by name and have it write the corresponding string to -LocationID]
Set-CsOnlineVoiceUser -Identity $Identity -TelephoneNumber $TN -LocationID ??????
Thanks in advance for any help you can provide.
Cheers
-Eric
All replies (4)
Tuesday, March 27, 2018 6:20 PM ✅Answered
I would scrap Read-Host and use Out-GridView. I don't have any way of testing the Skype for Business cmdlets but I think something like this should work:
$Locations = Get-CsOnlineLisLocation |
select LocationId, Location |
sort Location
$GridArguments = @{
OutputMode = 'Single'
Title = 'Please select a location and click OK'
}
$Location = $Locations | Out-GridView @GridArguments | foreach {
$_.LocationId
}
if ($Location) {
$Arguments = @{
Identity = $Identity
TelephoneNumber = $TN
LocationID = $Location
}
Set-CsOnlineVoiceUser @Arguments -WhatIf
# Remove -WhatIf if everything works as expected
}
Tuesday, March 27, 2018 3:56 PM
Use Write-Host to output a menu. Look in Gallery for examples of menu creation in PowerShell.
If you use your search engine you will find many blogs showing various methods of creating a menu,
As a quickie you can use "Out-GridView"
\(ツ)_/
Tuesday, March 27, 2018 4:00 PM
Research Switch statements in PowerShell, you could then assign a variable to a specific input. However, there are a number of ways you could achieve this functionality.
Please note that it is beyond the scope of most technical forums to write you a complete script.
Learn PowerShell Script Requests
-Remember to mark the correct response as the answer-
Tuesday, March 27, 2018 7:12 PM
That's exactly what I was looking for Leif-Arne. Thank you so much for the help!!!
Cheers!
Eric