Announcement

Collapse
No announcement yet.

Assist with a get-mailbox query please - enddateforretentionhold

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Assist with a get-mailbox query please - enddateforretentionhold

    Hi folks - I'm struggling with getting the output I'm hoping for with some cleanup for a client.

    Basically, we're trying to determine user accounts that can be removed after their 1 year retention period has expired.

    First, I gave myself a "one year ago" variable

    Code:
    $oneyearago = (get-date).addyears(-1).toshortdatestring
    and now, no laughing at my very inefficent code

    Code:
    get-mailbox -resultsize unlimited | where {($_.customattribute5 -eq "Departed") -and ($_.enddateforretentionhold -le $oneyearago)} | select displayname,hiddenfromaddresslistsenabled,enddateforretentionhold | sort-object enddateforretentionhold
    I've also tried this for my variable, with the same results

    Code:
    $oneyearago = (get-date).addyears(-1).toshortdatestring()
    Could I be running into a problem with the date formatting used in the EndDateForRetentionHold mailbox attribute causing it to not perform the math correctly?

  • #2
    Re: Assist with a get-mailbox query please - enddateforretentionhold

    It looks like enddateforretentionhold is a DateTime property.
    http://msdn.microsoft.com/en-us/libr...g.140).aspx#Y0

    The following command will convert to a string from a DateTime.
    Code:
    $oneyearago = (get-date).addyears(-1).toshortdatestring()
    Try:
    Code:
    $oneyearago = (get-date).addyears(-1)
    Or if you need just the date:
    Code:
    $oneyearago = (get-date).addyears(-1).Date
    or, to get the same exact thing as above:
    Code:
    [datetime]$oneyearago = (get-date).addyears(-1).toshortdatestring()
    This basically will convert the date to a string then back to a date.
    Regards,
    Jeremy

    Network Consultant/Engineer
    Baltimore - Washington area and beyond
    www.gma-cpa.com

    Comment


    • #3
      Re: Assist with a get-mailbox query please - enddateforretentionhold

      By Jove, I think you've got it!

      It looks like forcing it to [datetime] may have done the trick.

      Thank you Jeremy!

      Comment


      • #4
        Re: Assist with a get-mailbox query please - enddateforretentionhold

        Thanks very much for your help Jeremy. The following lines took care of the query

        Code:
        [datetime]$oneyearago = (get-date).addyears(-1).toshortdatestring()
        get-mailbox -resultsize unlimited | where {($_.customattribute5 -eq "Departed") -and ($_.startdateforretentionhold -lt $oneyearago)} |select displayname,hiddenfromaddresslistsenabled,enddateforretentionhold | sort-object enddateforretentionhold
        I should be able to take out from the select statement to the end, and replace it with Remove-Mailbox to quickly and easily clean stuff up.

        Comment


        • #5
          Re: Assist with a get-mailbox query please - enddateforretentionhold

          Glad to help.
          Regards,
          Jeremy

          Network Consultant/Engineer
          Baltimore - Washington area and beyond
          www.gma-cpa.com

          Comment

          Working...
          X