Hey folks,
just pulled together a small script that can be run as a scheduled task, to unmanage/remanage based on custom properties. Obviously, this can be done from the GUI, but in particular, this use case can be tailored for other examples (such as a recurring frequency, like every Friday at 7). While there is a legacy tool available that requires RDP to the server, the advantage here is that the script can be set once, then just by adjusting the custom properties, it can be easily adapted from the GUI.
While it would be easy to break the main loop into more functions, I just left as is so it's easier to follow the flows. (There is some simple logic to handle dates in the past).
The logic is fairly simple, set the time (in UTC), as custom properties. When the script runs it picks up that data. If the unmanage time is in the future, and sooner than the remanage, it will call the function to schedule. Otherwise, it will just remanage the node.
So in my example here, there is one node (the 2948) that will be unmanaged, and the others have a remanage time before the unmanage, so those will just remanage.



The time will be displayed on the node details page (note the time here is the local time, not UTC)

And when the time is matched it will then unmanage, and of course remanage after.

$VerbosePreference = "continue"
Import-Module SwisPowerShell
$swis = Connect-Swis -host YOURORIONSERVERNAMEHERE -Trusted
#Only retrieve details for nodes with both values set.
function Get-UnmanageTimesPerNode
{
$query = @"
select n.caption,n.NodeID, n.CustomProperties.UnManageTime, n.CustomProperties.ReManageTime
from orion.Nodes n
where n.CustomProperties.UnManageTime is not NULL
and n.CustomProperties.ReManageTime is not NULL
$results = Get-SwisData -SwisConnection $swis -Query $query
Write-Output $results
}
#invokes remanage verb for a node, then does a pollnow
function Invoke-RemanageNode ($swisconnection,$node,$nodeid)
{
write-verbose "Remanaging, and polling, $node ID: $nodeid"
Invoke-SwisVerb $swisconnection Orion.Nodes Remanage @("N:$nodeId")
Invoke-SwisVerb $swisconnection Orion.Nodes Pollnow @("N:$nodeId")
}
function Invoke-UnmanageNode ($swisconnection,$node, $nodeid, $starttime, $endtime)
{
write-verbose "Unmanaging $node ID: $nodeid"
Invoke-SwisVerb $swisconnection Orion.Nodes Unmanage @("N:$nodeId",$StartTime,$EndTime, $false)
}
########### Main Loop ###################
$times = Get-UnmanageTimesPerNode
foreach ($time in $times){
$node = $time.caption
$unmanagetime = $time.UnManageTime
$remanagetime = $time.ReManageTime
$nodeid =$time.NodeID
Write-verbose "$node (nodeid:$nodeid) has an unmanage time of $unmanagetime (UTC) and a remanage time of $remanagetime (UTC)"
if ($unmanagetime -lt $remanagetime -and ($unmanagetime -ge ((Get-Date).ToUniversalTime() ))){
Write-Verbose ("Unmanage time is in future, and remanage is after that, so scheduling.")
Invoke-UnmanageNode -swisconnection $swis -node $node -nodeid $nodeid -starttime $unmanagetime -endtime $remanagetime
}
#if remanage time is before unmanagetime, or remanage time is in the past just remanage.
else{
Write-warning ("$unmanagetime (UTC) is greater or equal to $remanagetime (UTC), or times are in the past. This will remanage $node")
Invoke-RemanageNode -swisconnection $swis -node $node -nodeid $nodeid
}
}
</code><code>