I'm trying to find a way to semi-automate the managing and unmanaging of nodes for monthly patching. I have been trying to use the PS module, but found the documentation on the github wiki lacking in how to incorporate the commands into a powershell script.
I found these two resources on Thwack, but they don't seem to be working
https://thwack.solarwinds.com/t5/Orion-SDK-Discussions/Mute-Alerts-in-SolarWinds-via-Powershell/m-p/296302
https://thwack.solarwinds.com/t5/Orion-SDK-Discussions/Powershell-scripts-to-automatically-unmanage-remanage-a-node/m-p/354841
My goal is to have the sys admin create a text file with the hostnames that they want to unmanaged, run the script, and the script will parse the names, find the corresponding node ID, and then unmanage it for 6 hours. if they want to manage the modes, the script will still parse the names, find the corresponding node ID, and they take effect immediately. I think the issue is with the swis related commands, but I didn't find enough in the documentation to explain how to do it.
Here is what I have so far:
#Silently Call SolarWinds SDK
Import-Module SwisPowerShell
<#if (!(Import-Module "SwisPowerShell" -ErrorAction SilentlyContinue))
{
Import-Module SwisPowerShell -ErrorAction SilentlyContinue
} #>
#prompt user for which option they way to select
write-host "`Which option do you want to do? n`n"
do {
write-host "M - Manage a list of servers in Solarwinds"
write-host "U - Unanage a list of servers in Solarwinds"
write-host "`n"
write-host "X - Exit"
write-host "`n"
write-host -nonewline "Type your choice and press Enter: "
$choice = read-host
write-host ""
$UorM = $choice -match '^[MmUuXx]+$'
if ( -not $UorM) {
write-host "`n"
write-host "Invalid selection" -ForegroundColor red
}
} until ( $UorM )
#write-host -nonewline "Type or paste the filename that contains the list of servers you want to set to unmanage: "
$filepath = "<folder path>list.txt"
#$Username = 'username@domainname.com'
#$UserPassword = 'Users Password'
#$creds = get-credential -Message "Please enter your credentials that you used to log onto the Solarwinds Orion Platform: "
$creds = Import-CliXml -Path "<encrypted admin creds>"
$LGcreds = $creds
$nodelist = Get-Content $filepath
#establish connection to the orion server
$swis = connect-swis -Host <OrionServerName> -Credential $LGcreds
try{
Write-Host "Verifying connection to Orion."
#verify the connection to the Orion Server is successful,
$swis.Open()
}
catch{
Write-Host $_.Exception.Message
}
$now =[DateTime ]:: Now
$later =$now.AddHours(6)
#if U is selected, then start the unmanage decision tree
if (($UorM -eq 'u') -or ($UorM -eq 'U')){
$nodelist | % { $nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName LIKE '$nodename%'"
Invoke-SwisVerb $swis Orion.Nodes Unmanage @("N: $nodeid ", $now ,$later , "false")
}
}
#if M is slected, than select the manage decision tree
elseif (($UorM -eq 'm') -or ($UorM -eq 'M')){
$nodelist | % { $nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName LIKE '$nodename%'"
Invoke-SwisVerb $swis Orion.Nodes Remanage @("N: $nodeid ", $now ,$later , "false")
Set-SwisObject $swis -Properties @{Remanage}
}
}
#otherwise, exit the stript
else {
break script
}
####### End of Script #############
once I get this working, I'd like to get the automated manage and unmanaged working, as we have a server (actually 3) that restart every day at 10pm, so I am hoping I can stop getting the alerts that the server is down at that time.