none
Splatting and Switch Parameters RRS feed

  • Question

  • Hey Scripting Guys!

    I do a lot of bulk work with PowerShell.   One of the things I have yet to be successful in is using a single csv input to bulk create mailboxes (room, equipment, shared).  I would like to have my script be able to read the mailbox type value from the csv and create it accordingly, without needing to either use multiple csv's (one for each type of mailbox) or build my script with 3 separate iterations of the 'new-mailbox' command.

    It would appear that there isn't a way to have a column contain the value (room or shared or equipment) and use that as the switch parameter for new-mailbox (-room, -shared, -equipment).   

    It was suggested to me to use splatting for this, but I am not really sure if it can work that way and if so, how I would go about formatting it.

    Can you shed some light here?


    • Edited by BejeweledOne Tuesday, May 30, 2017 1:50 PM
    • Moved by Bill_Stewart Friday, July 7, 2017 6:57 PM This is not "scripts on demand"
    Tuesday, May 30, 2017 1:38 PM

All replies

  • # assume csv column is MBType:
    
    $splat = @{
        name =  value
        ...
    }
    
    $splat.Add($csv.MBType,$true}
    
    


    \_(ツ)_/

    Tuesday, May 30, 2017 1:59 PM
  • To make sure I understand correctly...............

    $mailboxes = import-csv -path   xxxx\xx.csv

    foreach ($item in $mailboxes)

    {$splat = @{

          name = $mailboxes.name

          Alias = $mailboxes.alias

          Autoprocess = $mailboxes.autoprocess

    }

        $splat.Add($mailboxes.MBType,$True)

      new-mailbox @splat

    }


    Tuesday, May 30, 2017 2:22 PM