cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 10

Powershell Script Monitor not working

Jump to solution

Hello everyone! Really need some help trying to get this monitor off the ground.

We have a Windows Server 2008 Cluster and I'm trying to get the current owner of a resource. Unfortunately, I haven't seen anything in the Microsoft Windows Server 2008 Failover Cluster template that can do that or inform us if the resource has moved.

So we wrote a simple powershell script to tell us just that. The script executes successfully when run locally via the desktop. But for some reason, I can't seem to get to working using the PS script monitor. When I click get script output, it comes back as not defined

$fpstatus = cluster fpncluster res "alpha name" /status;

$fpcowner = $fpstatus[10];

$fpcowner = $fpcowner.substring(42,3);

if ($fpcowner -eq "alpha3"){

  write-host Message.Current Owner: ALPHA3;

  write-host Statistic: 3;

  exit 0;

  }

write-host Message.Current Owner: ALPHA4;

write-host Statistic: 4;

exit 2;

solarps.PNG

Can anyone assist?

1 Solution
Level 8

As Petr.Vilem‌ suggested, there is a possibility to use Get-WmiObject directly. Here is a tested example on W2k8 cluster:

try {

  $resName= $args[0];

  $whereClause= "name=""$resName""";

  $nodeName = Get-WmiObject -Authentication PacketPrivacy -Impersonation Impersonate -ComputerName ${IP} -Credential ${CREDENTIAL} -Namespace "root\MSCluster" -Class "MSCluster_NodeToActiveResource"|Where-Object {$_.PartComponent -match [regex]::escape($whereClause)}|ForEach-Object{$_.GroupComponent.Substring($_.GroupComponent.LastIndexOf('Name="')+6).TrimEnd('"')};

  Write-Host "Statistic: 1";

  Write-Host "Message: $nodeName";

  Exit 0;

}

catch {

  Write-Host "Statistic: 0";

  Write-Host "Message: $($Error[0])";

  Exit 1;

}

Variable $resName  is filled with the value taken from Script Arguments field. The switch -Authentication PacketPrivacy is necessary in case you are using older versions of PowerShell.

Hope this helps.

View solution in original post

14 Replies
Level 8

As Petr.Vilem‌ suggested, there is a possibility to use Get-WmiObject directly. Here is a tested example on W2k8 cluster:

try {

  $resName= $args[0];

  $whereClause= "name=""$resName""";

  $nodeName = Get-WmiObject -Authentication PacketPrivacy -Impersonation Impersonate -ComputerName ${IP} -Credential ${CREDENTIAL} -Namespace "root\MSCluster" -Class "MSCluster_NodeToActiveResource"|Where-Object {$_.PartComponent -match [regex]::escape($whereClause)}|ForEach-Object{$_.GroupComponent.Substring($_.GroupComponent.LastIndexOf('Name="')+6).TrimEnd('"')};

  Write-Host "Statistic: 1";

  Write-Host "Message: $nodeName";

  Exit 0;

}

catch {

  Write-Host "Statistic: 0";

  Write-Host "Message: $($Error[0])";

  Exit 1;

}

Variable $resName  is filled with the value taken from Script Arguments field. The switch -Authentication PacketPrivacy is necessary in case you are using older versions of PowerShell.

Hope this helps.

View solution in original post

Thank you vita‌! That was quite helpful!

My scripting and PS game isn't as strong, so it took me a while to decipher your script.

I know the script works because I ran it manually from a PS console. But when I test it in Solarwinds, the messages statistic keeps coming back as N/A.


Do you know if there is a way to debug the test so that I can see where there problem is popping up?

0 Kudos

Hello, egas,

here is a more readable version (hopefully):

try {

  $resName= $args[0];

  $whereClause = "e=""$resName""";

  $ns = "root\MSCluster";

  $c = "MSCluster_NodeToActiveResource";

  $wmiObjects = Get-WmiObject -Authentication PacketPrivacy -ComputerName ${IP} -Credential ${CREDENTIAL} -Namespace $ns -Class $c;

  foreach($wmiObject in $wmiObjects | Where {$_.PartComponent -match [regex]::escape($whereClause)} | Select -First 1) {

    $nodeName = $wmiObject.GroupComponent.Substring($wmiObject.GroupComponent.LastIndexOf('Name="')+6).TrimEnd('"');

  }

  Write-Host "Statistic: 1";

  Write-Host "Message: $nodeName";

  Exit 0;

}

catch {

  Write-Host "Statistic: 0";

  Write-Host "Message: $($Error[0])";

  Exit 1;

}

  • Debugging: in general you can use 'Windows PowerShell ISE', but in Orion console, you have to write your own debug messages (use Write-Host, Format-List, etc)
  • ${CREDENTIAL}: this macro gets expanded to the user name specified in the credential dialog. If you have domain trust or other way of authentication, you do not need it at all.

You've been quite helpful vita‌! Thank you!

0 Kudos

Much thanks vita‌ for the script!

I eventually removed the -Credential option and then it started working.

Thank you to everyone who assisted!

0 Kudos
Level 10

My experience with installing the agent.

I was having some difficulty pushing the agent from Solar to the remote machine so opted to install manually.

I had some issues installing manually. When prompted for Solar admin credentials, I used my AD account which was added to Solar and given admin privileges which did not work. I had to use the builtin Solar admin account.

Once it was installed manually, I tried to add the node Solar where it said it found it and needed to install some plugins which failed. I believe it needed a particular .Net

I ran a Windows Update which installed some .Net updates, rebooted twice and the I was able to successfully add the node to Solar.

That being said I am still having problems to execute my PS script on the node with the agent. Am I missing something?

0 Kudos

Would not getting info you are looking for via WMI be the alternative way? The powershell script would run locally on orion polling engine but it would make remote WMI connection to target machine. WMI namespace "root\MSCluster", class "MSCluster_NodeToActiveResource" seems to contain what you are interested in.

Hey Petr.Vilem‌, thanks for that suggestion. Truth be told, I'm not familiar with WMI at all and I was able to get the info I needed from PS hence the reason I took that route.

I will look into WMI option now that you say I may be able to get the info I need. If you have any resources that can help me get up to speed with WMI, I appreciate it.

0 Kudos

You may also want to change the platform setting from x86 to x64

SAM-Platform-Setting.gif

Also, I am assuming you have clicked on 'Assign Credentials' while doing this testing?

0 Kudos

Thanks for the feedback thus far HolyGuacamole both the platform and the credentials were as you advised. However, no luck as yet.

0 Kudos
Level 13

Format of message and statistic output must match, so try to change output part either to

write-host Message: Current Owner: ALPHA3;

write-host Statistic: 3;

or

write-host Message.CurrentOwner: ALPHA3;

write-host Statistic.CurrentOwner: 3;

Petr.Vilem‌, Thank you very much for you feedback! That was quite helpful! When I executed the code locally on the Solarwinds box, it began working as expected. I updated the script a bit as well.

$fpstatus = cluster fpncluster res "alpha name" /status;

$fpcowner = $fpstatus[10];

$fpcowner = $fpcowner.substring(42,3);

if ($fpcowner -eq "alpha3"){

  write-host Message: ALPHA3;

  write-host Statistic: 3;

  exit 0;

  }

if ($fpcowner -eq "alpha4"){

  write-host Message: ALPHA4;

  write-host Statistic: 4;

  exit 2;

  }

write-host Message: Error;

write-host Statistic: 0;

exit 1;

Unfortunately, I am still having difficulties executing this on the remote machine.

I do believe Winrm was setup correctly. I ran the quickconfigure and it did what it was supposed to do.

0 Kudos

installing an agent is one way to get around remote execution settings

HolyGuacamole‌, I am liking that idea!

I am gonna look into that.

If you have tips or helpful documentation that might assist, I would be grateful if you would share.

0 Kudos