10 Replies Latest reply on Aug 29, 2012 9:46 AM by tdanner

    PowerShell Script to Unmanage Hosts Connection Problems

    mik22

      Using SDK version 1.5 with NPM 10.2.2

       

      It seems I'm having problems connecting to my Solarwinds server using SDK. I
      try "$swis = Connect-Swis -host 'solarwindsserver.domain.com'" I get
      prompted for a user name and password but it doesn't seem to matter what I
      enter being it always seems to work. I then try "Get-SwisData $swis
      'SELECT NodeID, Caption FROM Orion.Nodes'" to see if I can read the
      database but get the below error in PowerShell]

       

       

      Get-SwisData : There was no endpoint listening at
      net.tcp://nau-mon01.naucom.com:17777/SolarWinds/InformationService/v3

       

       

      /Orion/ssl that could accept the message. This is often caused by an
      incorrect address or SOAP action. See InnerExcepti

       

       

      on, if present, for more details.

       

       

      At line:1 char:13

       

       

      + Get-SwisData <<<< $swis 'SELECT NodeID, Caption FROM
      Orion.Nodes'

       

       

      + CategoryInfo : NotSpecified: (:) [Get-SwisData], EndpointNotFoundException

       

       

      + FullyQualifiedErrorId :
      System.ServiceModel.EndpointNotFoundException,SwisPowerShell.GetSwisData

       

       

      I found this post http://thwack.solarwinds.com/thread/46537
      suggesting that the query may be returning too many results but adding a where
      clause "Get-SwisData $swis 'SELECT NodeID FROM Orion.Nodes WHERE SysName
      like somenode'" produces the following error leading me to believe the
      thread isn't related to my problem

       

       

      Get-SwisData : There was no endpoint listening at
      net.tcp://nau-mon01.naucom.com:17777/SolarWinds/InformationService/v3

       

       

      /Orion/ssl that could accept the message. This is often caused by an
      incorrect address or SOAP action. See InnerExcepti

       

       

      on, if present, for more details.

       

       

      At line:1 char:13

       

       

      + Get-SwisData <<<< $swis 'SELECT NodeID, Caption FROM
      Orion.Nodes WHERE SysName like nau-mon1'

       

       

      + CategoryInfo : NotSpecified: (:) [Get-SwisData], EndpointNotFoundException

       

       

      + FullyQualifiedErrorId :
      System.ServiceModel.EndpointNotFoundException,SwisPowerShell.GetSwisData

       

       

      I am able to use SWQL Studio connecting with Server Type "Orion (v2)
      AD" and I'm able to run queries. This leads me to believe "$swis =
      Connect-Swis -host 'solarwindsserver.domain.com'" needs something to tell
      it to connect using "Orion (v2) AD" but there doesn't seem to be an
      option from looking at "Orion SDK.pdf".

       

       

      I try "$swis = Connect-Swis -v2 -host 'solarwindsserver.domain.com'" and get the following error when running
      "Get-SwisData $swis 'SELECT NodeID, Caption FROM Orion.Node WHERE
      SysName=nau-mon01.naucom.com'"

       

       

      Get-SwisData : Invalid username or password.

       

       

      At line:1 char:13

       

       

      + Get-SwisData <<<< $swis 'SELECT NodeID, Caption FROM
      Orion.Node WHERE SysName=nau-mon01.naucom.com'

       

       

      + CategoryInfo : InvalidOperation: (:) [Get-SwisData],
      MessageSecurityException

       

       

      + FullyQualifiedErrorId : SwisError,SwisPowerShell.GetSwisData

       

       

      When using the same user name and password I use for SWQL Studio

        • Re: PowerShell Script to Unmanage Hosts Connection Problems
          tdanner

          What version of the product are you using?

           

          You were on the right track about needing to provide a parameter to Connect-Swis to let it know that you need to connect to the v2 address. That parameter is "-v2". It is mentioned in the "Orion SDK.pdf" file (under the description of Connect-Swis on page 24), but I can definitely see how that could be missed.

          • Re: PowerShell Script to Unmanage Hosts Connection Problems
            mik22

            I split this up into two separate scripts to fit our use one to unmanage and another to remanage.  If anyone has a better way to write the below scripts feel free to share. I’m new to PowerShell and this is what I came up with and works for our application. As always use the scripts at your own risk.

            Before using the code you need to install SDK and information on SDK can be found here. Once SDK is installed you need to install the SwisPowerShell.dll explained on pg. 21 of the Orion Software Development Kit PDF. The PDF is available in Program Files>SolarWinds Orion SDK>Technical Reference once you install SDK.

             

            Unmanage Hosts

             

            #This adds the snapin for Solarwinds to PowerShell so it understands the below code

            Add-PSSnapin SwisSnapin

             

            # Connect to Solarwinds server

            #You may have to play with the options in this command to get it to work. I had to use the -v2 to specify the connection parameters and

            #-Trusted to specify to use currently logged in user. That is the way I got it to work but there are other ways that may be better. More information

            #on this is on pg. 21-22 of the Orion Software Development Kit PDF

            $swis = Connect-Swis -v2 -Trusted -host 'SolarwindsServer.domain.com'

             

            #UnManage nodes

            #This grabs all computers in the AD OU call "Unmanage Node" as a distinguished name. You can get the distinguished name

            #by going to properties of the OU, Attribute tab

            #The "-Filter *" is to grab all the computers in that OU, you could specify certain ones if you wanted

            $nodes = Get-ADComputer -SearchBase "OU=Unmanage Node,OU=Prod,OU=Servers,DC=YourDomain,DC=com" -Filter *

             

            #This is a loop to Unmanage all computers found in the OU "Unmanage Node"

            #The second line assigns the attribute "DNShostname" to "nodename" and is used on the third line

            #to get the NodeID of the computer in Solarwinds to be used to Unmanage the node in the 7th line

            #The foruth line is just to output each node as it is remanaged. The fifth line gets the current

            #date and time and assigns it to "now" and the 6th line adds 6 hours to "now" and assigns it to

            # "later" leaving "now" as it was

            foreach($node in $nodes) {

            $nodename = $node.DNShostname

            $nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE DNS like '$nodename'"

            Write-Output "Re-managing $nodename : $nodeid"

            $now=[DateTime]::Now

            $later=$now.AddHours(6)

            Invoke-SwisVerb $swis Orion.Nodes Unmanage @("N:$nodeid",$now,$later,"false")


            Remanage Hosts

             

            #This adds the snapin for Solarwinds to PowerShell so it understands the below code

            Add-PSSnapin SwisSnapin

             

            # Connect to Solarwinds server

            #You may have to play with the options in this command to get it to work. I had to use the -v2 to specify the connection parameters and

            #-Trusted to specify to use currently logged in user. That is the way I got it to work but there are other ways that may be better. More information

            #on this is on pg. 21-22 of the Orion Software Development Kit PDF

             

            $swis = Connect-Swis -v2 -Trusted -host 'SolarwindsServer.domain.com'

             

            #ReManage nodes

            #This grabs all computers in the AD OU call "Unmanage Node" as a distinguished name. You can get the distinguished name

            #by going to properties of the OU, Attribute tab

            #The "-Filter *" is to grab all the computers in that OU, you could specify certain ones if you wanted

            $nodes = Get-ADComputer -SearchBase "OU=Unmanage Node,OU=Prod,OU=Servers,DC=YourDomain,DC=com" -Filter *

             

            #This is a loop to Remanage all computers found in the OU "Unmanage Node"

            #The second line assigns the attribute "DNShostname" to "nodename" and is used on the third line

            #to get the NodeID of the computer in Solarwinds to be used to remanage the node in the fifth line

            #The foruth line is just to output each node as it is remanaged

            foreach($node in $nodes) {

            $nodename = $node.DNShostname

            $nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE DNS like '$nodename'"

            Write-Output "Re-managing $nodename : $nodeid"

            Invoke-SwisVerb $swis Orion.Nodes Remanage @("N:$nodeid")

            1 of 1 people found this helpful