locked
ScriptingAgentConfig Extension-Cmdlets for Retention Policies? RRS feed

  • Question

  • I found this useful configuration file for applying a retention policy to new mailboxes via the extension-cmdlet service.

    The only question I have is - my "VIPs" have no retention policy.  So if this script can't just skip adding a retention policy for VIPs in the defined VIP database, can/should I create a retention policy that simply has no retention tags in it?  If I assign a policy to a user with no retention tags/definitions wouldn't that act like not having a retention policy by not enforcing anything?

    Config:

    <?xml version="1.0" encoding="utf-8" ?> 
      <Configuration version="1.0"> 
      <Feature Name="MailboxProvisioning" Cmdlets="New-Mailbox"> 
      <ApiCall Name="OnComplete"> 
      If($succeeded) { 
        $Name= $provisioningHandler.UserSpecifiedParameters["Name"] 
        $retpolicy = "Retention Policy 1" 
        $policy_vip = "Retention Policy VIP" 
        if($provisioningHandler.UserSpecifiedParameters["RetentionPolicy"] -eq $null){ 
             if((get-mailbox $Name).database.name -eq "VIP"){ 
                    Set-Mailbox -Identity $Name -RetentionPolicy $policy_vip 
             } 
             else{ 
                 Set-Mailbox -Identity $Name -RetentionPolicy $retpolicy 
             } 
        } 
      } 
      </ApiCall> 
      </Feature> 
      </Configuration>

    Reference:

    http://www.proexchange.be/blogs/exchange2010/archive/2011/08/31/using-the-scripting-agent-to-automate-some-basic-housekeeping-tasks.aspx

    Thanks!

    Monday, January 12, 2015 4:15 PM

Answers

  • That's Powershell code inside the XML. The last snipped you provided should run with no issues. You can further optimize is so the whole if block becomes:

        if($provisioningHandler.UserSpecifiedParameters["RetentionPolicy"] -eq $null){ 
             if((get-mailbox $Name).database.name -ne "VIP")
             { 
                 Set-Mailbox -Identity $Name -RetentionPolicy $retpolicy 
             } 
        } 

    • Proposed as answer by Niko.Cheng Tuesday, January 13, 2015 10:07 AM
    • Marked as answer by Niko.Cheng Monday, January 19, 2015 2:14 AM
    Monday, January 12, 2015 4:42 PM
  • That makes sense.  So basically it will add the retention policy to any mailbox created in a database that is not equal to the "VIP" database.

    That does seem cleaner.  I can then exclude that VIP database from automatic mailbox distribution so the service desk has to choose that database during VIP mailbox creation.

    Thanks for the help. :)

    • Marked as answer by Niko.Cheng Monday, January 19, 2015 2:14 AM
    Monday, January 12, 2015 4:45 PM

All replies

  • Also, I have thought about just cutting out the extra VIP stuff from the extension-cmdlet since this is only run during new-mailbox creation and shouldn't affect my current retention policy assignments.  I would just have to remember to exclude/remove the retention policy from any future VIP should they get an exclusion.  I only have 4 users with exclusions right now, out of 1300.  So it may not even be worth adding into the script for new-mailbox creation.
    Monday, January 12, 2015 4:19 PM
  • Removing the Set-Mailbox -Identity $Name -RetentionPolicy $policy_vip from the first if branch will achieve your goal - VIP users won't get assigned any retention policy while all the rest will. Or are you after something else ?
    Monday, January 12, 2015 4:27 PM
  • Well, that would be ideal.. still have a VIP database that won't apply a retention policy for new mailboxes created in that VIP database.

    Just removing that one line won't generate an error?  I've removed the variable for the VIP policy in the example as well since it shouldn't be applying a policy for anything created in the VIP database.

    <?xml version="1.0" encoding="utf-8" ?> 
      <Configuration version="1.0"> 
      <Feature Name="MailboxProvisioning" Cmdlets="New-Mailbox"> 
      <ApiCall Name="OnComplete"> 
      If($succeeded) { 
        $Name= $provisioningHandler.UserSpecifiedParameters["Name"] 
        $retpolicy = "Retention Policy 1"
        if($provisioningHandler.UserSpecifiedParameters["RetentionPolicy"] -eq $null){ 
             if((get-mailbox $Name).database.name -eq "VIP"){ 
             } 
             else{ 
                 Set-Mailbox -Identity $Name -RetentionPolicy $retpolicy 
             } 
        } 
      } 
      </ApiCall> 
      </Feature> 
      </Configuration>

    Monday, January 12, 2015 4:33 PM
  • That's Powershell code inside the XML. The last snipped you provided should run with no issues. You can further optimize is so the whole if block becomes:

        if($provisioningHandler.UserSpecifiedParameters["RetentionPolicy"] -eq $null){ 
             if((get-mailbox $Name).database.name -ne "VIP")
             { 
                 Set-Mailbox -Identity $Name -RetentionPolicy $retpolicy 
             } 
        } 

    • Proposed as answer by Niko.Cheng Tuesday, January 13, 2015 10:07 AM
    • Marked as answer by Niko.Cheng Monday, January 19, 2015 2:14 AM
    Monday, January 12, 2015 4:42 PM
  • That makes sense.  So basically it will add the retention policy to any mailbox created in a database that is not equal to the "VIP" database.

    That does seem cleaner.  I can then exclude that VIP database from automatic mailbox distribution so the service desk has to choose that database during VIP mailbox creation.

    Thanks for the help. :)

    • Marked as answer by Niko.Cheng Monday, January 19, 2015 2:14 AM
    Monday, January 12, 2015 4:45 PM