How to use Powershell script to unmanage the multiple nodes dhingraamit1 over 4 years ago
I am trying to use PowerShell script to unmanage the testweb5 and the testweb6 nodes in Solarwinds using for loop. I got something below but I am not sure of the syntax.
Please help ...
For ($i=5; $i-le6; $i++)
{String Syntax} Also I am not sure if you heard of Solarwinds but this is what I did when I had to unmanage one node using PowerShell script. Please see below something similar but for multiple nodes shown above for testweb and testweb6 $ErrorActionPreference="SilentlyContinue" Stop-Transcript | out-null $ErrorActionPreference = "Continue" Start-Transcript -path C:\UnmanageOutput.txt #Add SwisSnapin to the current PowerShell runspace Add-PSSnapin SwisSnapin #Connect to Orion Server $swis = Connect-Swis -Trusted -Hostname 'solarwinds.connectionsacademy.org' #Get Node Info $nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName = 'testweb5.ca-schools.org'" $nodeid = 871 #Unmanage Node $now = [DateTime]::UtcNow $later = $now.AddHours(1) Invoke-SwisVerb $swis Orion.Nodes Unmanage @("N:$nodeid",$now,$later,"false") Stop-Transcript
Bob McCoy over 4 years ago dhingraamit said: $nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName = 'testweb5.ca-schools.org'" $nodeid = 871
Why are you setting nodeid twice. Which one to you want to use? Also, why are you using a for loop, unless you are planning to do this to dozens/hundreds of machines. Why not an array of names? $nodes = "testweb5","testweb6" And then do a foreach loop through the nodes. dhingraamit1 over 4 years ago Thanks for the prompt response. That was just an example Basically right now we need to unmanage testweb5 and testweb6 in Solarwinds using PowerShell script somehow and if it works then I need some kind of script to unmanage all production servers production servers 100-150
So can you provide the whole syntax for the array of names and the for each loop through the nodes. I am quite a newbie in this so please provide me a step to step complete syntax on how to do this task Thanks and I really appreciate it. Also the nodeid=871 was for something else it is not linked with testweb5 and testweb6. Now I need the whole syntax for powershell script to unmanage these two for testweb5 and testweb6.
Bob McCoy over 4 years ago So would something like this do? #Add SwisSnapin to the current PowerShell runspace Add-PSSnapin SwisSnapin $nodeRange = 100..150 $now = get-date $later = $now.AddHours(1) #Connect to Orion Server $swis = Connect-Swis -Trusted -Hostname 'solarwinds.connectionsacademy.org' foreach ($node in $nodeRange) { #Get Node Info $nodeName = "nj2prdcnxweb" + $node + ".ca-schools.org" $nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName = `'$nodeName`'" #Unmanage Node Invoke-SwisVerb $swis Orion.Nodes Unmanage @("N:$nodeid",$now,$later,"false") }
dhingraamit1 over 4 years ago Let me try on this In the meanwhile I will appreciate if you can tell me with complete syntax just for testweb5 and testweb6 on how to unmanage those two. Thanks once again Bob McCoy over 4 years ago If you have a specific naming standard (e.g., 3-digt node number) and you are going to be using single or double digit numbers in the range, you can use the -f operator to format accordingly. For instance ... 71..110 | ForEach-Object {"{0:d3}" -f $_} Or in your case ... $nodeName = "nj2prdcnxweb" + ("{0:d3}" -f $node) + ".ca-schools.org" Bob McCoy over 4 years ago dhingraamit said:
In the meanwhile I will appreciate if you can tell me with complete syntax just for testweb5 and testweb6 on how to unmanage those two. Change $nodeRange = 100..150 To $nodeRange = 5..6 Change $nodeName = "nj2prdcnxweb" + $node + ".ca-schools.org" To $nodeName = "testweb" + $node + ".ca-schools.org" That is assuming you want to keep the domain name suffix, otherwise delete that part or change it to whatever is relevant in your test environment. Bob McCoy over 4 years ago If you have a discontiguous set of nodes, you can specify that as well. For instance ... $nodeRange = 5,21,47,83,111,(120..129),145 Matt M1 over 3 years ago Bob, I think this is very close to what I need. I was wondering if there is a way to build the array from a text file? We have 100-200 servers a week that have maintenance performed but these are not necessarily the same in any pattern based on who is working on what. We have a list that I can easily convert to a server.txt file with each server name on 1 line. What I would like to do is be able to unmanage each of the devices in orion from that list, then use the same list to re-enable management in orion. also to invoke a seperate script that takes the vmsnapshots for us, but that i can add later. Any help would be greatly appreciated. Bob McCoy over 3 years ago Matt, this is a very old thread. In the future, please start a new thread, referencing the original if necessary. Perhaps you could do something like this ... $servers = Get-Content -Path .\data.txt $servers.GetType() $servers.count