I created the script below:
Code: Select all
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
$statusOK = "ScriptRes:Ok:"
$statusBad = "ScriptRes:Bad:"
$statusBadContents = "ScriptRes:Bad contents:"
$PFPath = $args[0]
$output = $statusBadContents
try
{
$Result = Get-PublicFolderStatistics -Identity $PFPath -ErrorAction Stop
if ($Result.ItemCount -gt 0)
{
$output = $statusBad + $Result.ItemCount
}
else
{
$output = $statusOK + $Result.ItemCount
}
}
catch
{
$output = $statusBadContents + $PFPath
}
echo $output
The parameter is a Public Folder URI:powershell -Command %Script% %Params%
e.g.
Now the following error occures:'\SUB DE\11_Customer-Care.de\Error'
The Exchange Server is version 200723.04.2014 15:15:56 SCDEWORKER03: Customer_care.de\Error Unknown Error: Invalid result (Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version
2.
At C:\WINDOWS\TEMP\tmp-2224-48.ps1:1 char:13
+ Add-PSSnapin <<<< Microsoft.Exchange.Management.PowerShell.Admin
+ CategoryInfo : InvalidArgument: (Microsoft.Excha...owerShell.Ad
min:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad
dPSSnapinCommand
The term 'Get-PublicFolderStatistics' is not recognized as the name of a cmdlet
, function, script file, or operable program. Check the spelling of the name, o
r if a path was included, verify that the path is correct and try again.
At C:\WINDOWS\TEMP\tmp-2224-48.ps1:11 char:41
+ $Result = Get-PublicFolderStatistics <<<< -Identity $PFPath -ErrorAction
Stop
+ CategoryInfo : ObjectNotFound: (Get-PublicFolderStatistics:Stri
ng) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException) Shell Script