2 Replies Latest reply on Apr 19, 2016 8:12 PM by danabrash

    Setting NCM Global Connection Profile in script

    danabrash

      Hello,

       

      I've found that this will set my node properties to "Yes" for "Manage node(s) with NCM":

          Invoke-SwisVerb $swis Cirrus.Nodes AddNodeToNCM @($NodeId)

       

       

      But I'm unable to find a way to set the Global Connection Profile.

       

      I assume it's another verb(?), but I can't seem to put it together.

       

      I can get the profiles and select the ID for the one I want:

           $ConnectionProfiles = Invoke-SwisVerb $swis Cirrus.Nodes GetAllConnectionProfiles

           $NCMConnectionProfileId = ($ConnectionProfiles.ConnectionProfile.Name | ? {$_.'#text' -eq $NCMProfileName}).Id

       

      But I'm not sure how to get that associated with the node from there.

       

      TIA

          

       

       

        • Re: Setting NCM Global Connection Profile in script
          tdanner

          You can just set the ConnectionProfile property to the ID. Like this:

           

          Set-SwisObject $swis -Uri 'swis://localhost/Orion/Cirrus.NodeProperties/NodeID=$NcmNodeId' -Properties @{ConnectionProfile=$NCMConnectionProfileId}

            • Re: Setting NCM Global Connection Profile in script
              danabrash

              Hi, thank you, that works.

               

              I had to first get the NodeID from CirrusNodes (hence your use of NcmNodeId, which I missed at first).  To do that I used my existing Orion NodeId to get it:

                  $NCMNodeId = Get-SwisData $swis "SELECT NodeId FROM Cirrus.Nodes WHERE CoreNodeID = '$NodeId'"

               

              I looked into trying to just use the GetConnectionProfile verb here, but I can't find verb syntax documentation to save my life, so this works for now to get them all.

                  $ConnectionProfiles = Invoke-SwisVerb $swis Cirrus.Nodes GetAllConnectionProfiles @()

               

              Problem came up when trying to narrow down the field to just the one I want.  There is something I don't understand about ProfileIDs.  What I was doing in the original post wasn't working.

               

              What I was doing was coming up with the ID '135'.  I don't know where it's coming from.  My filter is wrong when I try to apply the name string to the '#text' value for the name node of the connection profile:

              PS C:\> $ConnectionProfiles.ConnectionProfile.Name | ? {$_.'#text' -eq $NCMConnectionProfileName} | FT -AutoSize

              Id  #text                 
              --  -----                 
              135 <SuperSecretProfileName>

              When I changed it to look for the Name.'#text' value of the ConnectionProfile node, I come up with an array of IDs:

              PS C:\> $ConnectionProfiles.ConnectionProfile | ? {$_.Name.'#text' -eq $NCMConnectionProfileName}

              Id                    : {132, 17}
              EnableLevel            : EnableLevel
              EnablePassword        : EnablePassword
              ExecuteScriptProtocol  : ExecuteScriptProtocol
              Name                  : Name
              Password              : Password
              RequestConfigProtocol  : RequestConfigProtocol
              SSHPort                : 22
              TelnetPort            : 23
              TransferConfigProtocol : TransferConfigProtocol
              UseForAutoDetect      : false
              UserName              : UserName

              I know from checking SQL what ID I want:

              SELECT * FROM NCM_ConnectionProfiles WHERE Name = <SuperSecretProfileName>

              ID Name
              17 <SuperSecretProfileName>

              So I've indexed my results to get the right ID:

              PS C:\> ($ConnectionProfiles.ConnectionProfile | ? {$_.Name.'#text' -eq $NCMConnectionProfileName}).Id[1]
              17

              I don't trust picking a static index because it's right in one case.  I'd like to know a better way to get a Single ConnectionProfile by name.

               

              Instead of writing out another URI, I figured out how to concat the one I had and make it work:

              $ProfileURI = $NewNodeObject.Uri.Replace("Orion.Nodes","Cirrus.NodeProperties")
              $ProfileURI = $ProfileURI.Replace($NodeID,$NCMNodeId)

              #  Set the NCM Connection Profile
              Set-SwisObject $swis -Uri $ProfileURI -Properties @{ConnectionProfile=$NCMConnectionProfileId}

              This was also working for me.

              # Write directly to database
              Invoke-Sqlcmd -ServerInstance $DatabaseServerName `
                            -Database $DatabaseName -Username $UserName -Password $SqlPwd `
                            -Query "UPDATE NCM_NodeProperties SET ConnectionProfile = $NCMConnectionProfileId WHERE CoreNodeID = $NodeID"

              Here's what I did in a single snippet:

              #Get the NCMNodeId
              $NCMNodeId = Get-SwisData $swis "SELECT NodeId FROM Cirrus.Nodes WHERE CoreNodeID = '$NodeId'"

               

              # Get all ConnectionProfiles in the system
              $ConnectionProfiles = Invoke-SwisVerb $swis Cirrus.Nodes GetAllConnectionProfiles @()

               

              # Pick just the ID for the profile name we want.
              $NCMConnectionProfileId = ($ConnectionProfiles.ConnectionProfile | ? {$_.Name.'#text' -eq $NCMConnectionProfileName}).Id[1]

               

              # re-Concat the URI for this update
              $ProfileURI = $NewNodeObject.Uri.Replace("Orion.Nodes","Cirrus.NodeProperties")
              $ProfileURI = $ProfileURI.Replace($NodeID,$NCMNodeId)

               

              #  Set the NCM Connection Profile
              Set-SwisObject $swis -Uri $ProfileURI -Properties @{ConnectionProfile=$NCMConnectionProfileId}