4 Replies Latest reply on May 17, 2011 12:55 PM by Anders Mortensen

    Extened Objects , created with PowerShell

      Hi ,

       

      Is it possible to create Extended Objects  with PowerShell Commands ?

       

      My actual goal is to have extended objects with Windows Update info.

       

      Available updates

      Last Update  date

       

      And maybe later on do compliance against these informations.

       

      /Anders Mortensen

       

       

      This PS does the trick:

       

      # ==================

      # Last patched and Available

       

      $objSession = New-Object -com "Microsoft.Update.Session"

      $Available= $objSession.CreateupdateSearcher().Search($criteria).Updates.Count

       

      $objSearcher= $objSession.CreateUpdateSearcher()

       

      $colHistory = $objSearcher.QueryHistory(1, 1)

       

      Foreach($objEntry in $colHistory)

      {

      $LastUpd=$objEntry.Date

      }

       

      echo "Available  $Available"

      echo "LastUpdate  $LastUpd"

       

       

        • 1. Extened Objects , created with PowerShell
          Gerardo Bartoccini

          Provided that the power shell commands are available on all your target servers, it should be quite straightforward.

           

          Put your script on your share/sensors dir or on your File server and then use scriptutil in your extended object.

           

          If power shell is not available on all your target servers then it's harder, as you need to copy the relevant binaries before you kick off the script.

          1 of 1 people found this helpful
          • 2. Extened Objects , created with PowerShell

            Hi

             

            Thanks for info.

             

            But I can't make it work, properbly I do it wrongly.

             

            I do :

            Put a file in //BLSERVER/opt/nsh/extended_objects/ab.ps1

            The file ab.ps1 is just simple for the test:

             

            $LastUpd="2011"

            $Available=17

            echo "Available=$Available"

            echo "LastUpdate=$LastUpd"

             

             

            Command:

            nexec -i  ??TARGET.NAME??  cmd /c "echo . | powershell -ExecutionPolicy RemoteSigned /opt/nsh/extended_objects/ab.ps1"

             

             

            Type: Central Execution

             

            Char encode: Default      ( also tried UFT-8 )

             

            Grammar file: name = value grammer (nsvp.gm)

             

            Note that without echo dot pipe PowerShell hangs, as diccusted before somewhere else.

            What am I missing ?

            /Anders

             

            • 3. Extened Objects , created with PowerShell
              Gerardo Bartoccini

              There are a few issues here.

              You put the file on the file server but the command you put in the EO definition doesn't refer to that.

              Furthermore, you need a file to be available on the target server, and the EO is not the right tool to copy file over.

              What you need to do is to create a script that "creates" your Powershell script on the target server, then runs it.

               

              I recommended to use scriptutil, which automatically copies the script over, executes it then removes it.

               

              Try with something like this:

               

              scriptutil -h ??TARGET.HOST?? -s //BLSERVER/opt/nsh/extended_objects/script.bat

               

              script.bat will contain:

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

              echo $LastUpd="2011" >> ab.ps1

              $Available=17 >> ab.ps1

              echo "Available=$Available" >> ab.ps1

              echo "LastUpdate=$LastUpd" >> ab.ps1

               

              echo . | powershell -ExecutionPolicy RemoteSigned ab.ps1

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

              • 4. Extened Objects , created with PowerShell

                Yes thanks ,

                 

                scriptutil  does the trick.

                It works, but I hoped I did not need to create the PS1 like that.

                The real PS1 is more than 4 lines.

                 

                Actually server name is not needed, as I want the EO to run from any BL server.

                 

                Thanks again

                 

                /Anders

                 

                This works:

                 

                scriptutil -h ??TARGET.HOST?? -s /opt/nsh/extended_objects/ab.bat

                 

                 

                 

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

                 

                echo $LastUpd="2011" > ab.ps1

                echo $Available=17 >> ab.ps1

                echo "Available=$Available" >> ab.ps1

                echo "LastUpdate=$LastUpd" >> ab.ps1

                echo . | powershell -ExecutionPolicy RemoteSigned .\ab.ps1