I have a powershell script that uses a list of hostnames in a CSV to unmanage in mass via the Orion SDK. I have the results of the script exported to a log file. The Unmanage reports as successful however the node magically remanages itself before the UnManageUntil time. See screenshots below
Script ran at 4:45pm using UnManageFrom time of Now (4:45pm) to UnManageUntil time of Now + 6 hours (10:45pm).
However at 6:45pm the node is managed again. And triggers a reboot alert when rebooted during our maintenance window. This occurred for every node I unmanaged with my script so its not an isolated incident.
Below is my powershell script. Is there something wrong with my script? What would make my nodes remanage exactly 2 hours after I unmanaged them and before they are set to?
Im running NPM 11.0.1 and SAM 6.1.1
Set-ExecutionPolicy RemoteSigned
Add-PSSnapin SwisSnapin
$HostnameList = @()
Import-Csv c:\Hostnames.csv | ForEach-Object {$HostnameList += $_.Hostname}
$cred = get-credential Admin
$swis = Connect-Swis -host "orionserver" $cred
$now=[DateTime]::Now
$later=$now.AddHours(6)
ForEach ($Hostname in $HostnameList)
{
$NodeID = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName LIKE '$Hostname' OR DNS LIKE '$Hostname'"
$NodeIDStr = "N:" + $NodeID
Invoke-SwisVerb $swis Orion.Nodes Unmanage @($NodeIDStr,$now,$later,"false") -ErrorAction SilentlyContinue | Out-Null
IF ($NodeID) {
$Hostname + " " + $NodeID + " has been UnManaged from " + $now + " until " + $later | Tee-Object C:\UnManageLog.txt -Append
}
ELSE {
$Hostname + " does not exist in SolarWinds or the Hostname is incorrect. Try FQDN." | Tee-Object C:\UnManageLog.txt -Append
}
}