What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Powershell script works from Powershell prompt but not from PRTG

Votes:

0

I have made a script that will give back the freespace on a quorumdisk for a cluster if the node you supplied as a parameter is active and if it is not active will return 0 with the text that it is not active.

This script is in the exe folder of main prtg server and it works fine if I run it from the powershell prompt but it wont give me back anything when it is executed from prtg itself. It does see the parameter but doesn't seem to be able to get anything from the get-wmiobject.

Any ideas?

This is the code :

param([string]$MACHINE)

if ($MACHINE -eq "")
{
 write-host "0:ERROR NO PARAMETER GIVEN"
 exit 2 
}
clear-host

# Define variables
# $MACHINE="zlm-webprd1"



# Get the currently active clusternode
[string]$CLUSTERNODE=Get-WmiObject -ComputerName $MACHINE -namespace "root/MSCluster" MSCluster_NodeToActiveGroup|%{$_.GroupComponent} 
[string]$CLUSTERNODE = [string]$CLUSTERNODE.Substring(20)

$CLUSTERNODE = $CLUSTERNODE -replace "`"",""

 

# Get the hostname from the currently connected system.
[string]$HOSTNAME=Get-Wmiobject -computername $MACHINE Win32_ComputerSYstem|%{$_.Name}

# Get the Quorum Disk
[string]$QUORUMDISK=Get-Wmiobject -computername $MACHINE -namespace "root/MSCLuster" MSCluster_ClusterToQuorumResource|%{$_.PartComponent}
[string]$QUORUMDISK = [string]$QUORUMDISK.Substring(30)
$QUORUMDISK = $QUORUMDISK -replace "`"",""


if ($CLUSTERNODE -eq $HOSTNAME)
 { 
  
  # Get the size and freespace of disk partitions and only select quorum disk
  $dsk= Get-WmiObject -computername $MACHINE Win32_LogicalDisk
  
  foreach ( $drive in $dsk ) 
  {
   if ($drive.name -eq $QUORUMDISK)
   { 
    [string]$TEMP1 = (($drive.Freespace)/($drive.size))*100
    [string]$TEMP1 = [string]$TEMP1 -replace " ",""
    write-host $TEMP1":ACTIVE"
   }
  }
  
 }
else
 {
  write-host "0:NOT ACTIVE"
  exit 1
 }

cluster powershell prtg quorum windows wmi

Created on Aug 13, 2010 11:17:08 AM

Last change on Aug 13, 2010 11:28:30 AM by  Daniel Zobel [Product Manager]



3 Replies

Accepted Answer

Votes:

0

Hello,

just to check the execution policy for powershell scripts is set to 'unrestricted'? Please bear in mind that there might be to powershell versions installed (32bit and 64bit) in case you use a 64bit Windows.

Best Regards.

Created on Aug 16, 2010 11:47:17 AM by  Torsten Lindner [Paessler Support]



Votes:

0

Stefan, did you end up getting this issue resolved? We've got a similar issue (with the get-counter command rather than wmi) and are set to unrestricted so would love to hear if the solution was something else. Thanks. James.

Created on Oct 12, 2010 12:51:56 PM



Votes:

0

Try running PowerShell 64bits and enabling the unrestricted permisions:

64bit version: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell_ise.exe

Run: set-executionpolicy unrestricted

Created on Jan 10, 2011 2:51:14 AM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.