Hi Everyone,
I am trying to get the powershell script monitor to return/read an integer statistic.
When I run it in PowerShell it returns the output/statistic, but also the session information.
So, when I do the same when creating a new component monitor in SAM, I get this error:
Output Result:
Get Output Failed:
Output: ==============================================
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- ------------
1 Session1 Usav-pwdb-sn... Opened Microsoft.PowerShell Available
66
'66' is the output/statistic that I want the powershell script monitor to read so that I can assign appropriate critical/warning thresholds to it.
Can you please help me to identify how I need to format output of script to just return the statistic?
Here is the script:
# Get Credentials
$User = "domain\username"
$PWord = ConvertTo-SecureString –String "dksladfs" –AsPlainText -Force
$Credential = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $PWord
# SQL Server Name
$SQLServer = "<FQDN host name>"
# Create PSsession for SQL Server
New-PSSession $SQLServer -Credential $Credential
$session = Get-PSSession
# Run Query on SQL Server
Invoke-command -ScriptBlock {
Import-Module "sqlps" -DisableNameChecking
$Result = Invoke-Sqlcmd -Query "select count(*),name from poeshoppingcarts psc with (nolock) inner join PoeCartStatus pcs with (nolock) on pcs.PoeCartStatusGuid=psc.PoeCartStatusGuid where name='submitted'group by name order by name desc" -ServerInstance "<FQDN host name" -Database "POE" -Username "SolarWinds" -Password 'blahblah' | select column1
$Return = $Result.column1
} -Session $session
# Output Variable from SQL Query $Return
$Return = Invoke-Command -Session $session -ScriptBlock { $return }
$Return
# Closes PS Remote Session to SQL Server
Remove-PSSession *