This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Powershell Script Monitor not working

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?

  • 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.

  • 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.

  • 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?

  • 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?

  • 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.

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

  • 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.

  • 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.