Your opinion and expertise asked

Welcome Forums General PowerShell Q&A Your opinion and expertise asked

This topic contains 4 replies, has 3 voices, and was last updated by

3 years, 7 months ago.

  • Author
  • #25747

    Points: 0
    Rank: Member

    I have a project to centralized management of all my Microsoft products : AD, Exchange, SharePoint and Lync for the moment. So I installed a Windows 2012 R2 server (core) dedicated to PowerShell administration. With the help of tommymaynard on this forum, I configure my PSWA to work like I wanted to. But now it's time to scripting what I need to do.

    My question is what's the best way for me to start.

    It is better to create a series of personal cmdlet (function) and did module with it or it is better to write big full script for all big action I need to do ?
    I'm not sure I'm clear. 🙁
    For example, create a new AD user. What's the best : Create cmdlet for each action with specific parameters to me and put this cmdlets in a little script or write a big script with all actions I need to perform to create a user.

    Another thing, it is a good idea to put a menu in the script? I did some and I want to know if it's a good or not. If it's yes, did I do it the best way? See my example:

    function Set-EmailAddress{
        $accountmodify = Read-Host "Enter the USERNAME of the account you want to ADD or REMOVE email address"
        $listemailadd = Get-Mailbox -Identity $accountmodify | Select -expand emailaddresses alias
        Write-Output "This is the list of all email address for the account $accountmodify"
        Write-Output $listemailadd
        $emailadd = Read-Host "Entrer the email address you want to add or remove"
        echo "--------------------------------------------"
        echo ""
        echo ""
        echo "   1. ADD a email address TO $accountmodify"
        echo "   2. DELETE a email address FROM $accountmodify"
        echo "   3. Return to main menu"
        echo ""
        echo "--------------------------------------------"
        $answeremailadd = Read-Host "Please make your selection"
        if ($answeremailadd -eq 1){Set-Mailbox $accountmodify -EmailAddresses @{add=$emailadd}}
        if ($answeremailadd -eq 2){Set-Mailbox $accountmodify -EmailAddresses @{remove=$emailadd}}
        if ($answeremailadd -eq 3){Get-MainMenu}

    Thank's in advance for your feedback and advice.

  • #25763

    Points: 24
    Team Member
    Rank: Member

    Hi Jeremie,

    Create one or more controller modules with functions specific to your organisation to invoke the AD, Exchange, SharePoint and Lync cmdlets with the correct parameters and order. Do not use Read-Host to ask for user input. Use function parameters (mandatory) and validation. Avoid Write-Output to relay information to the users. Use Write-Error, Write-Warning and Write-Verbose. If necessary set the VerbosePreference to Continue for all users to give them output without writing objects to the pipeline using Write-Output. Only use Write-Output to write proper objects to the pipeline to allow the creation of a flow of functions (A | B | C) for later automation.


  • #25767

    Points: 0
    Rank: Member

    Hi Daniel,

    Thank's for your input. I start to see how I will structure all of this.

    Just one thing, after I got my modules to invoke command to AD, Exchange, etc, did you guide me to write a script for each action I want to do or do I big script for each service with menus and all action I can want to make.
    What's your opinion?


  • #25772

    Points: 438
    Helping Hand
    Rank: Contributor

    Think of creating a Module. Your company is Lauzier International. All of your functions should use a custom naming scheme with LI in the name (e.g. Get-LIADUser). In Get-LIADUser, you would gather relevant AD properties to Lauzier Inc in order to pass in a pipeline to Set-LIADUser, Set-LIExchangeMailBox, Set-LILyncAccount. You could create separate modules for each or create a single LIAdministration module with all of the functions you need to perform tasks at LI.

  • #25790

    Points: 0
    Rank: Member

    Good idea. More easy to find.
    Thank's Rob.

The topic ‘Your opinion and expertise asked’ is closed to new replies.