- August 16, 2016 at 11:00 am #50575
Hi all, (new user here)
I am trying to create a script that would Speed up the process of enabling users with Skype for Business. I would like the script to pose a series of "questions" using I think Mandatory Parameters. Then the Admin just has to type in the Name of the user, the diferrent policys and so on. My main Problem at the moment is that I would like a set of text to Pop on Screen when running the script that lists the available policys. This can be manually typed into the script as we don't have to many different policys and it is just to future proof to help future admins with the names. Is there a way to do this ? I have googled around but just can't seem to find what I am looking for or I don't know how to look 🙂
Many thanks in advanceAugust 16, 2016 at 11:18 am #50579
As you've probably discovered you can't output any message before the PowerShell engine asks for values for the mandatory parameters.
However, you can use the ValidateSet attribute.
The neat thing about the attribute is that the values will show up in a Get-Help output.
Get-Help .\PolicyScript.ps1 -Syntax
Additionally you could add a HelpMessage attribute as well.
I hope that helps.August 16, 2016 at 11:32 am #50581
First of all thank you for your time,
the ValidateSet Attribute would achieve exactly what I want I was just unaware that was possible. My knowledge of available Features is growing slowly everyday. (Day 4 of working with powershell)
ThanksAugust 16, 2016 at 12:16 pm #50583
You're very welcome. Which material are you using to learn PowerShell? May be we can suggest additional material for you to study over the coming days and weeks.
Keep up the great work and welcome to the PowerShell community.
DanielAugust 16, 2016 at 12:32 pm #50585
I have a copy of Windows Powershell Best Practices by Ed Wilson sitting next to me,I and have managed to watch the whole Jump Start Videos on MVA (with J.Snover and J.helmick) which is awesome by the way. I would like to pick up Don's book at some Point when I have the Chance.
I am currently having a Problem getting the ValidateSet to work;
HelpMessage="Please use Pool Name",
I could post the whole script butI like to try and figure stuff out rather than just be told 🙂
MarcAugust 16, 2016 at 1:10 pm #50590
Are you getting an error? Is this the entirety of the Param block? What you have here would fail if it is the entire block since it has the comma and no close parenthesis. I ran it through ISE as it is below with no issue.
Param( [parameter(mandatory=$true, HelpMessage="Please use Pool Name", Position=1)] [ValidateSet("gimmi","stuff")] [string]$pool)August 16, 2016 at 1:29 pm #50592
No that is not all 🙂 I was just wondering if I was putting it in the right place at all within the Param Block. I would post everything that I have but to be honest I'm a little unsure of myself at the Moment. I only started "working" with PS on SaturdayAugust 16, 2016 at 1:56 pm #50598
Multiple parameter definitions in a param() block need to be separated by a comma.
Example 1 (Simple without additional parameter attributes like Parameter, ValidateSet, String, etc.):
param ( $Pool, $Name )
param ( [Parameter( Mandatory = $true, HelpMessage = "Please use Pool Name", Position = 1 )] [ValidateSet("gimmi","stuff")] [String] $Pool, # Multiple parameter definitions need to be separated by a comma [Parameter(Mandatory=$true)] [String] $Name ) $Pool $Name
August 16, 2016 at 1:57 pm #50601
- This reply was modified 1 month, 2 weeks ago by Daniel Krebs.
A benefit to posting it all is it allows us to see where you are going with it and gives us a chance to spot other inconspicuous things they may be the actual error. Also, now is a good time to get into good habits and we can (mostly) assist with that as well.August 16, 2016 at 2:07 pm #50605
HelpMessage="Please use SAM name",
HelpMessage="Please use Lineuri: tel:12341234ext=123(beispiel)",
HelpMessage="Please use Dialplan: Dialplan ohne Amtsholung",
HelpMessage="Please use Voice Policy: Default Policy",
Enable-csuser -identity $SAMname.Identity -registrarpool nawlync002.netatwork.de -sipaddresstype Emailaddress
# Pause for 30 seconds for AD Replication
write-host -foregroundcolor Green "Pausing for 2 Days to allow for AD Replication"
Start-Sleep -s 30
Set-CsUser -Identity $SAMname.Identity -enterprisevoiceenabled $True -lineuri $linuri
Grant-CsDialPlan -Identity $SAMname.Identity -PolicyName $dial.DialPlan
Grant-CsVoicePolicy -Identity $SAMname.Identity -PolicyName $voice.VoicePolicy
Gran-CsClientPolicy -Identity $SAMname.Identity -policyname PaderbornClientPolicy
This is without Validate,August 16, 2016 at 2:37 pm #50607
The param() block works fine on my machine. What happened to the parameters at position 2 and 3?August 17, 2016 at 6:15 am #50720
I made changes to the script and forgot to Change the Postion numbers,August 17, 2016 at 8:47 am #50732
No problem. Have you had the chance to get your function parameter validation working?
If not, please post the error message and/or screen output for us to help further.August 17, 2016 at 9:41 am #50738
I will be trying again this afternoon, I am currently on-site at a customer. I will let you know how it goes,
MarcAugust 17, 2016 at 9:53 am #50747
PS C:\Users\mdryburgh\Documents> Enable-CsuserNAW Cmdlet Enable-CsuserNAW an der Befehlspipelineposition 1 Geben Sie Werte für die folgenden Parameter an: (Geben Sie zum Aufruf der Hilfe !? ein.) SAMname: TJones Linuri: 123456 Dial: !? Please use Dialplan: Dialplan ohne Amtsholung or Default Policy Dial: Bannana Voice: Teddybear Enable-CsuserNAW : Das Argument für den Parameter "Dial" kann nicht überprüft werden. Das Argument "Bannana" gehört nicht zu dem vom ValidateSet-Attribut angegebenen Satz "Default Policy;Dialplan ohne Amtsholung". Geben Sie ein Argument an, das in dem Satz enthalten ist, und führen Sie dann den Befehl erneut aus. In Zeile:1 Zeichen:1 + Enable-CsuserNAW + ~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Enable-CsuserNAW], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Enable-CsuserNAW
You must be logged in to reply to this topic.