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 Component Monitor permissions issues

I created this basic test powershell component monitor that fails with the following error message when I run it

Get-Counter : Unable to access the desired computer or service. Check the permissions and authentication of the log service or the interactive user session against those on the computer or service being monitored.

# This gets a Windows performance counter from the specified IP

$counter = Get-Counter "\\${IP}\LogicalDisk(C:)\free megabytes"

$size = $counter.CounterSamples.CookedValue / 1000    # Size to GB

Write-Output "Statistic.Drive:0"

Write-Output "Message.Drive:$size"

The credentials used to run the monitor have domain admin privileges and are the same for every other component monitor and system poller.

These same credentials are local admin access to the SAM.

The line above is successful if I test run the component monitor against the SAM server (so ${IP} is the localhost)

WMI is allowed through the Windows Firewall on each server and they are all on the same VLAN

The strange thing however, is that the line works if I log into the SAM server with the same SAM service account, fire up a PowerShell console and run the Get-Counter command to query a server other than localhost

$someRemoteServer = "1.2.3.4"

Get-Counter "\\$someRemoteServer\logicaldisk(c:)\free megabytes"

If the SAM server itself can directly query other server's performance counters, what is preventing the Windows PowerShell Component Monitor using the same credentials?

Any help would be great.

  • I'm not an expert on Powershell, but when writing the SAM Custom Template Guide, I learned ${IP} can sometimes cause odd issues. Have you tried the macro ${Node.DNS}?

    I'm sure someone can help out! anglia-admin, I'll keep watch on your question to help add more best practices and troubleshooting to the new guide in case anyone else has a similar issue.

    Thanks!

  • I don't think the credentials on the component are getting passed through to the script.  Get-Counter may be one of the cmdlets that doesn't allow for credentials to be specified and will only send whatever account was used to kick off the command (i.e. the one used to start the Windows service for the poller).  It kind of sounds like when you try to hit a UNC and Windows just sends over the credentials you're logged in with and bounces back a login prompt if it doesn't work.  Replacing the Get-Counter line with a wmic command would let you specify credentials and could be a good test.  If that's the case, wmic should solve the problem or at least get you closer to what you're looking for.

    Alternatively, you could also try using WinRM and Invoke-Command with the Get-Counter cmdlet.  Invoke-Command has a credential option as well.  Something like this might work:

    $gimmedatcounter = Invoke-Command -Computer {$IP} -Scriptblock { Get-Counter "\LogicalDisk(C:)\free megabytes" } -Credential '${Credential}'

    WinRM and Powershell made it possible for me to collect TCP connections by port on remote servers using netstat, so we have become best friends emoticons_happy.png

    Best of Luck!

  • Do you know how powershell commands are processed in a SAM environment as I thought it invokes a ps command line in the background (effectively running "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"), or is there a built in interpreter that is seperate to the powershell component on the host SAM server?

    I ask because this would explain some of the other incompatibilities I have found converting some of my scripts to run in SAM.

    Your WinRM idea is good but that is not enabled by default which would mean I would have to go through change control and I'm trying to avoid that if possible, but it's an option.

    Thanks.

  • Very weird, even if I spawn a new PowerShell process using .Net classes, with the main script in a separate file, the script still fails with a credential based error...even I supply the process with the correct credentials.

    $process = New-Object System.Diagnostics.Process

    $process.StartInfo.FileName = "powershell.exe"

    $process.StartInfo.UseShellExecute = $false

    $process.StartInfo.RedirectStandardOutput = $true

    $process.StartInfo.Username = "solarwinds"

    $process.StartInfo.PasswordInClearText = "*****"

    $process.StartInfo.Arguments = "c:\scripts\Get-DiskSpace.ps1"

    $process.Start()

    $out = $process.StandardOutput.ReadToEnd()

    $process.WaitForExit()

    Write-Output "Statistic.Drive:0"

    Write-Output "Message.Drive:$out"

  • I'm struggling with the same exact error for the following Powershell monitor

    $count= get-counter "\\SERVER\Web Service(INSTANCE)\Current Connections"

    write-host "Statistic.count"

    There has to be a way to execute this! Alternatively, this one does work with the built in Windows Process Monitor

  • I have had this before trying to run scripts from SAM against a remote computer and it was a rights issue.

    The machine running SAM had insufficient rights to execute the script on the remote computer.

    The way I solved it was to add the Sam Computer 'MySamComputer@companyxyz' as a local admin on the remote machine.

    Do this the same way you would normally add a user into the administrators group but there is a 'computers' check box that is normally not checked

    and most people don't pay attention to. Just find your computername and add it and then your script should run.

  • Doh!

    Even though I had specified to use the service account, I had not clicked the little check box Run the script under specified account: in the component monitor definition.

    My script now works in it's simple form.

    Arggh...Oh well...Thanks for any help all emoticons_happy.png

    <#

        SolarWinds PowerShell monitor checks drive free space

        Takes drive letter and threshold (in GB) as argument

    #>

    $size = Get-Counter ("\\${Node.DNS}\LogicalDisk(" + $args[0] + ":)\free megabytes")

    $size = ($size.CounterSamples.CookedValue) / 1000 # Size in GB

    if ($size -gt $args[1]) {

        Write-Output "Statistic.Drive:0"

        Write-Output "Message.Drive:$size"

        exit 0

    } else {

        Write-Output "Statistic.Drive:0"

        Write-Output "Message.Drive:$size"

        exit 1

    }

  • Good tip on the ${Node.DNS} macro.

    Thanks.

  • Great info! I'll add some tips, troubleshooting, and info to the Custom Template Guide on PowerShell scripting.

  • Hi Anglia,

    while i am trying to enable monitoring via shell script, facing error shown in screenshot, can you please suggest any recommendation here

    pastedImage_0.png