When I run this cmdlet, I get the expected output.
However, when I run this as a PowerShell script, it returns nothing. What am I doing wrong? Please assist. Thanks!!
Add-PSSnapin *Exchange*
$user = Read-Host "Add displayName here..."
Get-MailboxDatabase | Get-MailboxStatistics -Filter "DisplayName -like '*$($user)*'" | Where-Object {$_.DisconnectDate} | Format-Table DisplayName, MailboxGuid, Database, DisconnectDate
-Filter
This parameter is available only in on-premises Exchange.
[...]
* Enclose the whole OPath filter in double quotation marks " ". If the filter contains system values (for example, $true, $false, or $null), use single quotation marks ' ' instead. Although this parameter is a string (not a system block), you can also use braces { }, but only if the filter doesn't contain variables.
[...]
* Value is the property value to search for. Enclose text values and variables in single quotation marks ('Value' or '$Variable'). If a variable value contains single quotation marks, you need to identify (escape) the single quotation marks to expand the variable correctly. For example, instead of '$User', use '$($User -Replace "'","''")'. Don't enclose integers or system values (for example, 500, $true, $false, or $null).
Open in new window
a try.
Or
Open in new window