Trying to create a function that will mute a node on the fly and I am getting the following error:
Invoke-SwInvoke-SwisVerb : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At line:41 char:9
+ Invoke-SwisVerb -SwisConnection $Swis -EntityName $Entity -Ve ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-SwisVerb], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,SwisPowerShell.InvokeSwisVerb
Here is my code:
</code><pre class="code codeBlock" spellcheck="false" tabindex="0">function Mute-SWNode {
[CmdletBinding()]
param(
[Parameter()]
[String] $MuteNode
)
#Create Connection to SWIS data
$Creds = Get-Credential -UserName "Username" -Message "Enter Admin Credentials"
$SwisCreds = $Creds
$SwisHost = "OrionServer"
$Swis = Connect-Swis -Hostname $SwisHost -Credential $SwisCreds
$Entity = 'Orion.AlertSuppression'
#Isolate Node Name
$GetNodeCaption = @"
SELECT DISTINCT [Nodes].Caption
FROM Orion.AlertObjects
JOIN Orion.Nodes ON Nodes.Caption = AlertObjects.RelatedNodeCaption
WHERE AlertObjects.RelatedNodeCaption = '$($MuteNode)' AND AlertObjects.EntityType = 'Orion.Nodes'
"@
$NodeCaption = Get-SwisData -SwisConnection $Swis -Query $GetNodeCaption
$NodeCaption = $NodeCaption | ForEach-Object { [string]$_ }
#Isolate Alert Uri
$GetNodeUri = @"
SELECT DISTINCT
[Nodes].AlertObjects.EntityUri
FROM Orion.AlertObjects
JOIN Orion.Nodes ON Nodes.Caption = AlertObjects.RelatedNodeCaption
WHERE AlertObjects.RelatedNodeCaption = '$($MuteNode)'"
"@
$NodeUri = Get-SwisData -SwisConnection $swis -Query $GetNodeUri
$NodeUri = $NodeUri | ForEach-Object { [string]$_ }
if ($NodeCaption -eq $MuteNode) {
Invoke-SwisVerb -SwisConnection $Swis -EntityName $Entity -Verb SuppressAlerts -Arguments $NodeUri @($NodeUri,[DateTime]::UtcNow) | Out-Null
#Write-host $Swis
}
}</pre><code>