2 Replies Latest reply on May 14, 2014 2:45 AM by leinhard

    how can make script working for multiple nodes.

    leinhard

      Dear, Team

      want to using the powershell script to using os version check multiple nodes in the WEST group

      see the following script plz

       

       

      ===================================================================

      if (! (Get-PSSnapin | where {$_.Name -eq "SwisSnapin"})) {

          Add-PSSnapin "SwisSnapin"

      }

       

       

      #Prep File

      $File = "C:\OS_CHECK.txt"

       

       

      $hostname = "127.0.0.1"

      $username = "admin"

      $password = New-Object System.Security.SecureString

      $cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

      $swis = Connect-Swis -v2 -host $hostname -cred $cred

       

      $group= 'WEST'

      $nodeId = get-swisdata $swis "SELECT NodeID FROM Cirrus.Nodes WHERE NodeGroup='$group'"

       

      $script ="sh run"

       

      #how can i change below lines to apply to multiple nodes ???

       

      $nodeIdList = New-Object -TypeName "System.Guid[]" 1

      $nodeIdList[0] = $nodeId

      Invoke-SwisVerb $swis Cirrus.ConfigArchive Execute @($nodeIdList, $script, $username) | Out-Null

      $transferID = "{$nodeId}:${username}:ExecuteScript"

       

      do {

          Start-Sleep -Seconds 1

          $status = Get-SwisData $swis "SELECT T.Status, T.Error FROM Cirrus.TransferQueue T WHERE T.TransferID=@transfer" @{transfer=$transferID}

          #Write-Host $status.Status

      }

      while (($status.Status -ne 'Complete') -and (-not $status.Error))

       

      $output = Get-SwisData $swis "SELECT T.Log FROM Cirrus.TransferQueue T WHERE T.TransferID=@transfer" @{transfer=$transferID}

       

      write-host $output

       

       

      $output | Out-File $File

       

       

      Write-Host "Process Completed!!"

        • Re: how can make script working for multiple nodes.
          tdanner

          If you want to run the same script on multiple nodes as a single NCM job, just change how the node list is built:

           

          $nodeIdList = New-Object -TypeName "System.Guid[]" 2

          $nodeIdList[0] = $nodeId

          $nodeIdList[1] = $anotherNodeId


          And so on for however many nodes you have.

          1 of 1 people found this helpful
            • Re: how can make script working for multiple nodes.
              leinhard

              I solved this program :-)

              thank you tdanner.

              reference below plz

              ==============================================

              if (! (Get-PSSnapin | where {$_.Name -eq "SwisSnapin"})) {

                  Add-PSSnapin "SwisSnapin"

              }

               

               

              $date=Get-Date -format "yyMMddhh"

               

               

              $File = "C:\$date-OS_CHECK.txt"

              #write-host $File

              #break

               

               

               

               

              $hostname = "127.0.0.1"

              $username = "admin"

              $password = New-Object System.Security.SecureString

              $cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

              $swis = Connect-Swis -v2 -host $hostname -cred $cred

               

               

              $group=read-host "Input Localtion"

              $IOS=read-host "Input IOS Version"

               

               

              $nodeId = get-swisdata $swis "SELECT NodeID FROM Cirrus.Nodes WHERE NodeGroup='$group'"

               

               

              $count = 0

              foreach ($node in $nodeId) {

               

               

                $Caption = get-swisdata $swis "SELECT NodeCaption FROM Cirrus.Nodes WHERE NodeId='$node'"

                $IOS_Ver = get-swisdata $swis "SELECT OSVersion FROM Cirrus.Nodes WHERE NodeId='$node'"

               

               

                If ($IOS_Ver -match $IOS)

                {

               

               

                 $output = "$Caption $IOS_Ver OK"

                 write-host $output

                   $output | Out-File $File -append

                }

                Else

                {

                $output = "$Caption $IOS_Ver FAIL"

                       write-host $output

                  $output | Out-File $File -append

                }

                      $count = $count + 1

               

               

              }

              $count = "Total : $count Devices"

              $count | Out-File $File -append

              Write-Host "$count Completed."