Category Archives: Scripts

PowerShell Function Get-MenuInput

I was recently working on a script with a unique requirement.  There was a desire to automate a business process, but there were also a number of exceptions and special cases.  In the end we decided to try and filter/select the best options then present them to the user running the script and have them make the final decision.

As part of that script I created a handy little function that accepts an array virtually any length and collects the users input as to which one we should use.  For example you could pass a list of all Lync Registrar pools in North America and get input as to which one we should use for provisioning.

Feel free to use or adapt this as needed, just leave a comment below if you find it useful or see any improvements.

function Get-MenuInput {
        Allow the user to choose an option from a menu.
        This function prints a menu list to the screen based on a supplied array.
        It allows the user to choose and option based on
        the number index and returns the chosen value as a string.
        $Pool = Get-MenuInput -Array (Get-CsService -Registrar).PoolFqdn
        Get-MenuInput -Array $Array -Prefix "DialPlan:"
        .PARAMETER Array
        String Array of available menu options.
        .PARAMETER Prefix
        Text string to add to the front of each options.
        Returns the single chosen array item
    param (
        [Parameter (Mandatory = $true)]

    #Note how many objects are in the array.
    #Number of menu options
    $ArrayLength = $Array.Length

    #Print each option in the array with a numbered choice index
    #Do While Loop is used to validate the users input
    Do {
        #Reset the Numbered Choice Index
        $i = 1

        #Write a line to the host for each item
        foreach ($item in $Array) {
            Write-log -Level Info -Data "$i - $Prefix$item"

            #Increment the Choice Index

        #Save the users choice as a variable
        $MenuChoice =  Read-Host -Prompt 'Please Choose the number of the desired option' 

    } While ($MenuChoice -lt 1 -or $MenuChoice -gt $ArrayLength)

    #Decrease the variable by one to convert to an array index that starts with 0
    $MenuChoice = $MenuChoice - 1

    #Log the choice
    Write-Host "$($Array[$MenuChoice]) Chosen." -ForegroundColor Green

    #Return the chosen option as a string


As always this is provided AS IS with no warranty or guarantee.  Use at your own risk.

Lync Documentation Script

I don’t like documentation, but it is a necessary evil.  It is important to document a Lync configuration for easy access to key information as well as tracking changes over time.  However since I do not enjoy it, nor do I know anyone who does, I have started scripting documentation where possible.

Below is my current script for documenting a Lync 2010/2013 environment.  Although it will run with Lync 2010, PowerShell 3.0 or later is required which is not installed by default on Lync 2010 servers.  It is still a work in progress, use at your own risk etc. etc.




Updating AD Telephone Numbers based on LineURI

I had a situation come up the other day during a Lync Voice installation.  The users LineURI in Lync was correct, but the Telephone number field in AD had been poorly maintained in both inconsistent formats and incorrect numbers.  I ended up writing a couple lines of PowerShell that they could use to update the Telephone field based on the LineURI, that they could then either run at intervals or put into a scheduled task.

Continue reading