?
Solved

PowerGui script that will display the last time a user accessed mailbox

Posted on 2010-01-11
11
Medium Priority
?
1,955 Views
Last Modified: 2012-05-08
I have a script configured that queries all my Exchange 2003 SP2 servers and display a list of mailboxes that are inactive for more than 60 days.  Whenever I execute the script the operation stops running due to the two errors listed below:
1.  Exception calling "ConvertToDateTime" with "1" argument(s): "Exception calling "ToDateTime" with "1" argument(s): "Specified argument was out of the range of valid values. Parameter name: dmtfDate"" (Select-Object)    At line: 5 char: 105

2.  Cannot convert argument "1", with value: "", for "op_Subtraction" to type "System.TimeSpan": "Cannot convert null to type "System.TimeSpan"."    At line: 5 char: 208

Here is the script:
$Servernames='server01','server02','server03','server04'
Get-WmiObject Exchange_Mailbox -Namespace root\MicrosoftExchangeV2 -ComputerName @($Servernames)| select MailboxDisplayName,@{n="LastLogonTime";e={$_.ConvertToDateTime($_.LastLogonTime)}},LastLoggedOnUserAccount,StorageGroupName,StoreName,ServerName | Where-Object { ((Get-Date)-$_.LastLogonTime).Days -gt 60}  
0
Comment
Question by:jahhan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
11 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 26284948

Has the date conversion worked in the past? WMI has it's own that I've always found more effective for this. Alas I have no Exchange 2003 system to test this on these days so you'll have to help me out there.

Chris
0
 

Author Comment

by:jahhan
ID: 26285443
Chris-Dent,
This has never worked in the past.   I first implemented this script last week, and ever since its first execution I have received this error message.  It displays information from several mailboxes, but its never over 5 records.  I have about 100 mailboxes that should be displayed, but the script stop running after it hits the first server that generates the error.

SatyaPathak,
My environment is 2003 so I cannot use the powerpack that is listed in the URL.
0
WatchGuard's M Series Appliances - Miecom Approved

WatchGuard's newest M series appliances were put to the test by Miercom.  We had great results and outperformed all of our competitors in both stateless and stateful traffic throghput scenarios! Ready to see how your UTM appliance stacked up? Download the Miercom Report!

 
LVL 71

Expert Comment

by:Chris Dent
ID: 26285457

Fancy trying this one? I wrote it for 2003 quite a while ago:

http://www.indented.co.uk/2009/01/22/exchange-2003-get-mailboxstatistics/

If it doesn't accept your array of servers as an argument let me know and I'll modify it. Otherwise it'll just need the Where-Object part, and possibly a Select-Object if you want fewer fields.

Chris
0
 

Author Comment

by:jahhan
ID: 26285994
Chris-Dent,
I'm a newbie to powerscript.   I copied the script from the website, do I have to modify anything to have it reach out to my Exchange boxes (Example change modify the $Servername= to read $Servername=Server01)?  Do I need to install the Exchange 2007 Power Management Script?
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 26286055

No and no :)

Copy and paste the function into PowerShell as is.

Lets see if this will combine it properly with your snippet above.

Chris
$Servernames= 'server01', 'server02', 'server03', 'server04'

$Servernames | %{ Get-2003MailboxStatistics -Server $_ } | `
  Select-Object MailboxDisplayName, LastLogonTime, LastLoggedOnUserAccount, `
    StorageGroupName, StoreName, ServerName | `
  Where-Object { $_.LastLogonTime -gt (Get-Date).AddDays(-60) }

Open in new window

0
 

Author Comment

by:jahhan
ID: 26286155
Below is the error message I receive:
The term 'Get-2003MailboxStatistics' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.      At line: 6 char: 44            
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 26287040

You pasted the function from my blog in prior to that? It needs to be loaded into the shell before it can be used.

It makes the full code into this.

Chris
Function Get-2003MailboxStatistics {
  Param(
     [String]$Identity = "",
     [String]$Server = $Env:ComputerName,
     [String]$Database = ""
  )

  $Filter = "ServerName='$Server'"
  if ($Database -ne "" ) {
    $Filter = "$Filter AND StoreName='$Database'"
  }
  if ($Identity -ne "") {
    $Filter = "$Filter AND (MailboxGuid='{$Identity}' OR LegacyDN='$Identity'"
    $Filter = "$Filter OR MailboxDisplayName='$Identity')"
  }

  Get-WMIObject -ComputerName $Server `
    -Namespace "root/MicrosoftExchangeV2" -Class "Exchange_Mailbox" `
    -Filter $Filter | `
  Select-Object `
    AssocContentCount, `
    @{n='DateDiscoveredAbsentInDs';e={
      If ($_.DateDiscoveredAbsentInDs -ne $Null) {
        [Management.ManagementDateTimeConverter]::ToDateTime(`
          $_.DateDiscoveredAbsentInDs)
      }} }, `
    MailboxDisplayName, TotalItems, LastLoggedOnUserAccount, `
    @{n='LastLogonTime';e={ if ($_.LastLogonTime -ne $Null) { `
      [Management.ManagementDateTimeConverter]::ToDateTime($_.LastLogonTime)}}
    }, `
    @{n='LastLogoffTime';e={ if ($_.LastLogoffTime -ne $Null) { `
      [Management.ManagementDateTimeConverter]::ToDateTime($_.LastLogoffTime)}}
    }, `
    LegacyDN, `
    @{n='MailboxGuid';e={
      ([String]$_.MailboxGuid).ToLower() -Replace "\{|\}" }}, `
    @{n='ObjectClass';e={ "Mailbox" }}, `
    @{n='StorageLimitStatus';e={ `
      Switch ($_.StorageLimitInfo) {
        1 { "BelowLimit" }
        2 { "IssueWarning" }
        4 { "ProhibitSend" }
        8 { "NoChecking" }
        16 { "MailboxDisabled" } }} }, `
    DeletedMessageSize, Size, `
    @{n='Database';e={
      "$($_.ServerName)\$($_.StorageGroupName)\$($_.StoreName)" }}, `
    ServerName, StorageGroupName, StoreName, `
    @{n='Identity';e={ ([String]$_.MailboxGuid).ToLower() -Replace "\{|\}" }}
}

$Servernames= 'server01', 'server02', 'server03', 'server04'

$Servernames | %{ Get-2003MailboxStatistics -Server $_ } | `
  Select-Object MailboxDisplayName, LastLogonTime, LastLoggedOnUserAccount, `
    StorageGroupName, StoreName, ServerName | `
  Where-Object { $_.LastLogonTime -gt (Get-Date).AddDays(-60) }

Open in new window

0
 

Author Comment

by:jahhan
ID: 26288309
So I plugged in this script and it is now asking me for my identity, server, and database.  Is this suppose to happen?  If so, I was looking for a script that retrieves all my mailboxes without typing in anything.
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 26291145

You mean it's prompting you for those? Shouldn't be, it has default values for each and they're all optional not mandatory.

Well never mind, it's only quicker if it works for you, saved me having to write the same code again. Here's a new version built only to do this task.

Chris
$Servernames= 'server01', 'server02', 'server03', 'server04'

Get-WMIObject -ComputerName $Servernames `
    -Namespace "root/MicrosoftExchangeV2" -Class "Exchange_Mailbox" | `
  Select-Object MailboxDisplayName, `
    @{n='LastLogonTime';e={ if ($_.LastLogonTime -ne $Null) {
      [Management.ManagementDateTimeConverter]::ToDateTime($_.LastLogonTime)}} }, `
    LastLoggedOnUserAccount, StorageGroupName, StoreName, ServerName | `
  Where-Object { $_.LastLogonTime -gt (Get-Date).AddDays(-60) }

Open in new window

0
 

Author Closing Comment

by:jahhan
ID: 31675536
Chris-Dent,
Thank you so much for your help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
A couple of months ago we ran into an issue that necessitated re-creating our Edge Subscriptions. However, when we attempted to execute the command: New-EdgeSubscription -filename C:\NewEdgeSub_01.xml we received an error indicating that the LDAP se…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question