Hello,
I was curious if Swis Powershell supports/works well with Multithreading? I use poshrsjob module to perform the multithreading, and I tried using it yesterday in a fairly simple way to update a status on a bunch of interfaces, but it seems to take a really long time. I'll share my code below.
#================= Import our Modules
if((Get-Module -ListAvailable -Name "PoshRSJob") -or (Get-Module -Name "PoshRSJob"))
{
Import-Module PoshRSJob
}
else
{
Install-Module -Name PoshRSJob -Scope CurrentUser -Force -Confirm:$False
Import-Module PoshRSJob
}
if((Get-Module -ListAvailable -Name "SwisPowerShell") -or (Get-Module -Name "SwisPowerShell"))
{
#Import-Module SwisPowerShell
}
else
{
Install-Module -Name SwisPowerShell -Scope CurrentUser -Force -Confirm:$False
Import-Module SwisPowerShell
}
#================= Connect to Solarwinds
if($NULL -eq $swis)
{
$swis = Connect-Swis -Hostname "Solarwinds" -Trusted
Try
{
$swis.Open()
}
Catch
{
Write-Host $_.Exception.Message
}
}
#======== Set our Credentials for Solarwinds
if($NULL -eq $wmiCredentialID)
{
$wmiCredentialsName = "SVC_SolarWinds"
$wmiCredentialID = ((Get-SwisData -SwisConnection $swis "SELECT ID, Name, Description, CredentialOwner FROM Orion.Credential WHERE Name = '$wmiCredentialsName'") | Where-Object { $_.CredentialOwner -eq "Orion"}).ID
}
#=================
#Grab all Interfaces that are WMI SubType and Unknown Status
$Interfaces = Get-SwisData $swis "SELECT NodeID, InterfaceID, Status, StatusIcon, InterfaceResponding, ObjectSubType, FullName, URI FROM Orion.NPM.Interfaces WHERE ObjectSubType = 'WMI' AND Status = '0'"
$Interfaces | Start-RSJob -Throttle ([int]((($Interfaces | Measure-Object).count)/4)) -Batch "Interface-Update" -ScriptBlock {
Param($Interface)
#$Interface
$UpdateInterface = @{
Status = 1
StatusIcon = "Up.gif"
InterfaceResponding = 1
}
Set-SwisObject $using:swis -Uri $Interface.uri -Properties $UpdateInterface -ErrorAction SilentlyContinue
Invoke-SwisVerb -SwisConnection $using:Swis -EntityName "Orion.Nodes" -Verb PollNow -Arguments @("IW:" + $Interface.InterfaceID)
} | Wait-RSJob -ShowProgress | Receive-RSJob