none
Scripting Creation and Configuration of Exchange 2007 Resource Mailboxes RRS feed

  • Question

  • I'm pretty green with powerhsell in terms of scripting. I'm trying to write a basic script that takes input from a semi-colon delimited CSV file and creates/configures resource mailboxes in Exchange 2007.

    My semi-colon delimited csv file is as follows

    Name;MaxCapacity;ResourcesinRoom;CalendarIncrementOption;Calendarworkweek;Maxdays;MaxMeetingDuration;HybridPerms;AutomaticPerms;ManualPerms;Delegates;FullAccess;CustomText
    Example-x1;35;"VTCEquipment, LCDProjector";15;M-F 7-5;365;7200;email.addy@example.com,another.email@example.com;j.g@example.com;ex@example.com;ex@example.com;"This is the exact text as it will be displayed in the reply to the meeting organizer"

    My script is as follows, although keep in mind I intended this to be called from the Exchange Managment Shell so the Exchange cmdlets were pre-loaded.

    $rooms = import-csv c:\temp\room-import2.csv -delimiter ';'
    $rooms | ForEach-Object -Process {New-Mailbox -name $_.name -alias $_.name -database "server\database" -userprincipalname "$_.name@example.com" -OrganizationalUnit "conference rooms" -DisplayName $_.name -Room}
    $rooms | ForEach-Object -Process {set-mailbox -identity $_.name -resourcecustom $_.resourcesinroom -resourcecapacity $_.maxcapacity}
    $rooms | ForEach-Object -Process {Add-MailboxPermission –Identity $_.name -User $_.fullaccess -AccessRights Fullaccess -InheritanceType all}
    $rooms | ForEach-Object -Process {Set-MailboxCalendarSettings -identity $_.name -AutomateProcessing:AutoAccept -addadditionalresponse:$true -additionalresponse $_.customtext -addnewrequeststentatively:$true -addorganizertosubject:$true -allbookinpolicy:$true -allowrecurringmeetings:$true -AllRequestOutOfPolicy:$true -AllRequestinPolicy:$true -bookingwindowindays $_.maxdays -bookinpolicy $_.automaticperms -deleteattachments:$true -deletenoncalendaritems:$true -enableresponsedetails:$true -enforceschedulinghorizon:$true -forwardrequeststodelegates:$true -maximumdurationinminutes $_.maxmeetingduration -organizerinfo:$true -removeforwardedmeetingnotifications:$true -removeoldmeetingmessages:$true -requestinpolicy $_.manualperms -requestoutofpolicy $_.hybridperms -resourcedelegates $_.delegates -scheduleonlyduringworkhours:$true -tentativependingapproval:$true}
    

    I'm having two issues with the script.

    1. During the set-mailbox command, there are some rooms that have multiple resources in the room (VTCEquipment and an LCDProjector). The cmdlet needs a specific format when multiple resources are to be input. For the parameter -resourcecustom, the cmdlet is expecting an input as follows: -resourcecustom ("VTCEquipment","LCDProjector") . The problem I am having is that when the string from the array is passed to the command, it is enclosed in double quotes. So I end up with something like -resourcecustom "("VTCEquipment","LCDProjector")" . The cmdlet returns an error stating it is an invalid input for that parameter. How can I edit my code to pass the string properly to the parameter?
    2. During the Set-MailboxCalendarSettings command, if I input one email address for any of the permissions fields (automaticperms, hybridperms, manualperms), it runs fine, if I input two or more it returns this error:

      Set-MailboxCalendarSettings : Object "email.addy@example.com, another.email@example.com" could not be found. Please make sure that it was spelled correctly or specify a different object. At C:\temp\test.ps1:9 char:62+

      $rooms | ForEach-Object -Process {Set-MailboxCalendarSettings <<<< -identity $_.name -AutomateProcessing:AutoAccept -addadditionalresponse:$true -additionalresponse $_.customtext -addnewrequeststentatively:$true -addorganizertosubject:$true -allbookinpolicy:$true -allowrecurringmeetings:$true -AllRequestOutOfPolicy:$true -AllRequestinPolicy:$true -bookingwindowindays $_.maxdays -bookinpolicy $_.automaticperms -deleteattachments:$true -deletenoncalendaritems:$true -enableresponsedetails:$true -enforceschedulinghorizon:$true -forwardrequeststodel

      egates:$true -maximumdurationinminutes $_.maxmeetingduration -organizerinfo:$true -removeforwardedmeetingnotifications:$true -removeoldmeetingmessages:$true -requestinpolicy $_.manualperms -requestoutofpolicy $_.hybridperms -resourcedelegates $_.delegates -scheduleonlyduringworkhours:$true -tentativependingapproval:$true}

      + CategoryInfo: NotSpecified: (0:Int32) [Set-MailboxCalendarSettings], ManagementObjectNotFoundException + FullyQualifiedErrorId : D05EA68E,Microsoft.Exchange.Management.Recipient Tasks.SetMailboxCalendarSettings

    Can anyone help me iron out the last wrinkles in this code? Alternatively, if you already have a script that does this, I am open to it. I would however like to know what I am doing wrong just for my reference.

     

    On a tangent, can anyone recommend a good book or online resource for teaching yourself Powershell scripting?

     

    Thanks,

    Jon






    • Moved by Alan.GimModerator Thursday, April 21, 2011 5:17 AM script-related (From:Admin)
    Wednesday, April 20, 2011 9:18 PM

All replies

  • 1.  Either enclose the entire string in single quotes:

    -resourcecustom '("VTCEquipment","LCDProjector")'

    or escape the double quotes:

    -resourcecustom "(`"VTCEquipment`",`"LCDProjector`")"

    The escape character is the back-tick, or unshifted tilda ("~") on most keyboards.

    2.  What did you set $Rooms to?  It doesn't look like it's the right collection to pipe to a ForEach-Lbject.  I can't comment further without seeing what it is you're trying to do.


    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Wednesday, April 20, 2011 9:41 PM
  • Thanks Ed,

     

    1. I'm a bit unclear where you are thinking I should make this modification.  Are you referring to me modifying the contents of the CSV file or the contents of the script itself?  I have tried editing both the script and the csv file with the escape characters and single quotes.  Still having the issue.  All I am looking for is when the string is passed from the variable $rooms, I want to drop the double quotes that are automatically appended.  In the CSV file I have entered ("LCDProjector","VTCEquipment").  After this string is passed to the command, it ends up as "("LCDProjector","VTCEquipment")"  (notice the extra set of double quotes).  All I want to do is either drop the double quotes, or somehow (after modifying my CSV to drop the parenthesis) use the script to append the parenthesis rather than entering them into the csv file.

    2. I simply am calling $rooms = import-csv filename -delimiter ';'.  The contents of that particular csv file are posted in the original post.  Let me know if there is any more info that I can provide that will make this more clear, but the contents of the originaly post should have all the info necessary to run the script from the EMS. 

     

    Thanks,

    Jon

    Thursday, April 21, 2011 8:38 PM
  • 1.  What exactly are you trying to pass to the -ResourceCustom property?  Are you trying to pass multiple properties?  If so, then try this technique:

    $a =  "LCDProjector,VTCEquipment"

    $aa = $a.split(",")

    What you end up with is an array of two strings, LCDProjector and VTEquipment.  I think that's what you're going to have to pass to the -ResourceCustom property.  Note the format, no quotes (except on the outside to put the comma in the CSV if necessary), no parentheses.

    2.  I think that my answer to 1 applies here too.  You have to turn the property into an array.

    I'm sorry that I'm not in a position to test this for you.


    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Friday, April 22, 2011 12:54 AM