Submit a ticketCall us

Get a crash course on Network Monitoring delivered right to your inbox
This free 7-day email course provides a primer to the philosophy, theory, and fundamental concepts involved in IT monitoring. Lessons will explain not only how to perform various monitoring tasks, but why and when you should use them. Sign up now.

Home > Success Center > Server & Application Monitor (SAM) > PowerShell script that uses VMware PowerCLI functions in SAM

PowerShell script that uses VMware PowerCLI functions in SAM


When you try to run PowerShell script in SAM that uses VMware.VimAutomation.Core snapin, you receive the following error message:


"Add-PSSnapin : The type initializer for 'VMware.VimAutomation.Sdk.Interop.V1.CoreServiceFactory' threw an exception. At line:31 char:13 + add-pssnapin <<<< VMware.VimAutomation.Core + CategoryInfo : NotSpecified: (:) [Add-PSSnapin], TypeInitializationException + FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.PowerShell.Commands.AddPSSnapinCommand"


All SAM versions


It is possible to configure the PoweShell Script Monitor in SAM to correctly load this snapin (using Remote Mode and other advanced settings.) However, connecting to the VMware server using the Connect-VIServer command consumes memory (up to 400 MB) and the polling job fails with an “Out Of Memory” exception. It is not practical to run this type of script in SAM.


Workaround: Use the Windows Script Monitor with a Visual Basic script as a wrapper for the PowerShell script.

  1. Place you PowerShell script in a folder where everyone can access it (e.g. C:\Windows\Temp\MyVMwareScript.ps1)
  2. Create the Windows Script Monitor with following script body:


fileName = "C:\Windows\Temp\MyVMwareScript.ps1"

Set objShell = CreateObject("Wscript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" & strComputer & "\root\cimv2")

Set colSettings = objWMIService.ExecQuery ("SELECT Architecture FROM Win32_Processor")

For Each objProcessor In colSettings
    If objProcessor.Architecture = 9 Then
              powerpath = "%windir%\sysnative"
       Exit For
    ElseIf objProcessor.Architecture = 0 Then
       powerpath = "c:\windows\system32"
       Exit For
    End If

Set vPSscrIpt = objShell.Exec( powerpath + "\windowspowershell\v1.0\powershell.exe " + fileName)

Do While vPSscrIpt.Status = 0
    WScript.Sleep 100

WScript.Quit vPSscrIpt.ExitCode


The PowerShell script is now executed in an external poweshell.exe process (not in SAM's JobEngineWorker.exe process) and the text output with an exit code is passed to SAM through the outer VB script.


Note: Only exit codes 0 (Up) and 1 (Down) are allowed in this case.



*** PLEASE NOTE *** 


SolarWinds support does not support custom scripting.  Please use the above information at your own discretion.   


Last modified
08:23, 2 May 2017