Test Exchange Powershell

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
RobertDerheld
Posts: 3
Joined: Wed Apr 23, 2014 8:16 am

Test Exchange Powershell

Post by RobertDerheld »

I want to use a Test with help of the Script Manager.

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 start cmd is:
powershell -Command %Script% %Params%
The parameter is a Public Folder URI:
e.g.
'\SUB DE\11_Customer-Care.de\Error'
Now the following error occures:
23.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
The Exchange Server is version 2007
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Do you use x64 Windows?
Then you have two Powershell versions: 32-bit and 64-bit.
Have you tried to run this script in shell (32-bit and 64-bit)?
If script works on 64-bit powershell, you may tell HostMonitor to use 64-bit Powershell:
e.g.
copy C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe c:\win64copy\powershell.exe
then specify Start CMD like:
c:\win64copy\powershell.exe -Command %Script% %Params%

Note1: According to first error message, there is no snap-ins registered in Powershell version. You may use Get-PSSnapin -Registered command to check registered snap-ins.
RobertDerheld
Posts: 3
Joined: Wed Apr 23, 2014 8:16 am

Post by RobertDerheld »

Thank you for your quick response.

to make a copy of the 64bit version of the powershell.exe to another folder not managed by the OS solved the problem.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Have you tried to run this script in Powershell shell (32-bit and 64-bit)?
RobertDerheld
Posts: 3
Joined: Wed Apr 23, 2014 8:16 am

Post by RobertDerheld »

I tried the script with the 32 and the 64 bit version of powershell.

using the 64 version everyting worked fine.

using the 32 bit version terminated with errors.

the exchange Snapin was only registered for the 64 bit version, not for the 32 bit version (as far as I can see the Snapin is only available as 64 bit version)

when I tried to start the script with the 64 bit version by
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe
the 32 bit version was started instead because the OS redirected the call to
C:\WINDOWS\SysWOW64\windowspowershell\v1.0\powershell.exe
For this I copied the 64 bit version of powershell to the folder (as mentioned in your answer above)
c:\KSTests
and configured KS Hostmon to use this version of powershell.
Now the OS does no redirect and everything workes fine.
Post Reply