8 Replies Latest reply on Jan 31, 2013 10:09 AM by Yanick Girouard

    How to run VB Script via Bladelogic extended Object

      Hi,

       

      I want to run some VB Script to fetch some data for reporting / compliance. Just curious to know how to run VB script via extended object  to get info and use into compliance Job??

       

       

      For example.

       

      Case "TEAMING" ' Is Teaming in use?

       

       

      RetrievedValue = ComponentList(Pointer).CookbookValue ' Set a default









      set Data = oWMI.ExecQuery("Select Caption From Win32_NetworkAdapterConfiguration where IPEnabled=True")







      For Each Element in Data


      FoundTeaming = False

      If InStr(UCase(Element.Caption),"TEAMING")>0 or InStr(UCase(Element.Caption),"BASP VIRTUAL ADAPTER")>0 Then ' we have a Teamed NIC

      FoundTeaming = True






      Exit For






      End If

        • 1. Re: How to run VB Script via Bladelogic extended Object
          Joe Piotrowski

          Configuration > Config Object Dictionary View

          From the pull down menu at the top left select Extended Objects

          Select the green + sign to create a new Extended Object

          Select "Extended Object" > Next

           

          Here is where you can specify the OS, the script, and the type of output (grammar file) so BSA can parse it properly.

          • 2. Re: How to run VB Script via Bladelogic extended Object

            Thanks for your reply

             

            Yes i know the mentioned steps , thing is that i am adding my script but unable to run it under BL Console opting Remote execution option??

            • 3. Re: How to run VB Script via Bladelogic extended Object

              Hi,

               

              Any update on how to run VBScript in BL via extended object??

               

               

              -Raj

              • 4. Re: How to run VB Script via Bladelogic extended Object
                Joe Piotrowski

                Raj, unfortunately I don't use VB so I cannot help you troubleshoot this further. If you don't get assistance here you can create a Helpdesk ticket for support.

                • 5. Re: How to run VB Script via Bladelogic extended Object
                  Steffen Kreis

                  Hi Raj,

                   

                  we have done something very similiar but using PowerShell.

                  In order to achieve that i have written an NSH script called psHelper.

                   

                  It basically takes 3 parameters.

                   

                  - Script

                  - Target

                  - Target_Dir

                   

                  Using these values it copies the script to the specified directory on the target, goes there, executes the script with nexec and then removes the script again.

                   

                  Using an appropriate output incl. the correct grammar file you can create compliance-rules for your output.

                   

                   

                  Here is a snippet from the Helper script for PS, which i think can easily be adjusted for VB:

                   

                  -------------------------------------------------------------------------------------

                  -------------------------------------------------------------------------------------

                  #!/bin/nsh

                   

                  #Statics

                  BLFS=blabla

                  SENSORS_SCRIPT=$1

                  TARGET=$2

                  DIR=$3

                   

                   

                  #As a first step we have to verify if PowerShell exists on the target

                  nexec $TARGET c:\\Windows\\system32\\reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\PowerShell"  > NUL 2>&1

                   

                  if [ $? -ne 0 ] ; then

                      echo "<Status><StatusExtendedObject>failed</StatusExtendedObject><Error>Powershell not found</Error></Status>"

                      exit 0

                  fi

                   

                   

                  cp //$BLFS/$SENSORS_SCRIPT //$TARGET/$DIR/$SENSORS_SCRIPT

                   

                  cd //$TARGET/$DIR

                   

                  nexec -i -e cmd /c "mode 1000,50 && echo . | c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe ./$SENSORS_SCRIPT"

                   

                  rm $SENSORS_SCRIPT

                   

                   

                  -------------------------------------------------------------------------------------

                  -------------------------------------------------------------------------------------

                   

                   

                  The helper script lives on our File-Server.

                  And will be called like this:

                   

                  nsh -c "//OUR_FS_SERVER/psHelper powershell_script.ps1 ??TARGET.NAME?? ??TARGET.STAGING_DIR??"

                   

                   

                  Hope this helps, Please let me know if you have any further questions.

                   

                  Cheers

                  Steffen

                  1 of 1 people found this helpful
                  • 6. Re: How to run VB Script via Bladelogic extended Object
                    Yanick Girouard

                    You can't just run native vbs scripts using an extended object (using scriptutil to launch it), because vb scripts will run in graphical mode by default. Instead you need to use cscript //nologo to call a vbscript that you create or copy on the fly on the target.

                     

                    One way to do this, is to echo your whole vbscript to a new file on the target using either a windows batch file or a NSH script. We've done it with either one, but the NSH script method had better success for us.

                     

                    Here's a simple nsh script you can use:

                     

                    echo "WCScript.Echo \"MESSAGE=Hello World!\"" > /c/Windows/Temp/script.vbs
                    nexec -e cscript //nologo C:\\Windows\\Temp\\script.vbs

                     

                    Save this in a new file on your file server (i.e. let's say your file server's called blfs) and then create an extended object like this:

                     

                    Name: Hello_World_VBS

                    Command: nsh -c "//blfs/path_to_eo_script.nsh" ??TARGET.NAME??

                    Type: Central Execution

                    Grammar: Windows INI

                     

                    Some things to consider is the escaping of NSH special characters in your VBS script string. What I usually do is that I edit my vbs separately in a text editor, and when I'm ready to paste it in my NSH script, I do this in that order:

                     

                    replace \ by \\\\

                    replace " by \"

                     

                    I then copy the whole thing and paste it between the double-quotes. Also make sure to escape the \'s in the Windows path of the cscript command or it will fail.

                     

                    Hope that helps !

                    1 of 1 people found this helpful
                    • 7. Re: How to run VB Script via Bladelogic extended Object
                      himanshu sangwan

                      Hi Raj,,,

                       

                      Please follow the below steps to run VB script via BBSA for compliance rule creation...Just replace my test VB script with your VB script & follow the steps 1 by 1 it should work because this is working in my environment here...Please let me know if it resolves your problem...

                       

                      Thanks

                      hsangwan

                       

                       

                       

                      How to run VB script under extended Object for creating compliance rules

                      Step 1   Create a nsh wrapper script and save it anywhere in target machine.

                       

                      -----------------------------------------------------------------------------------------------

                      # --- .vbs-Runner script ---

                       

                      # path where the vbs is created. Parameterize if needed  tPATH="/c/temp/__temp_vb_script.vbs"

                       

                      # Variable define for the file name

                      filename=`basename $0`

                       

                      if ! [ -d "/c/temp" ]

                      then

                       

                      mkdir -p /c/temp

                      tPATH="/c/temp/__temp_vb_script.VB-$ filename.vbs"

                       

                      else

                       

                      tPATH="/c/temp/__temp_vb_script.VB-$filename.vbs"

                       

                      fi

                       

                      # Create the vbscript to be executed

                      cat <<EOF > $tPATH

                       

                      WScript.Echo "Starting vbscript"

                       

                       

                      1. Wscript.echo "My very first script."

                       

                      1. WScript.Echo "Finished vbscript"

                      EOF

                       

                      # Get the host to run on

                      tHOST=`pwd | cut -d/ -f3`;

                       

                      # convert script path to Windows-style

                      tVBS_PATH_WIN=$(echo -E $tPATH | sed 's,/,\\,g')  tVBS_PATH_WIN=$(echo -E $tVBS_PATH_WIN | sed 's,\\c,C:,g')

                       

                      # Run the vbscript

                      nexec $tHOST cscript //NoLogo "$tVBS_PATH_WIN"

                       

                       

                      Save the file with the name <some-thing>.nsh

                       

                       

                      Step 2.

                       

                      Create new Extended Object with the below settings:-

                       

                       

                       

                      runscript  -h ??TARGET.NAME?? -p 2 -e //ip-address-where-test.nsh saved/c/tmp/test.nsh

                       

                      Step 3

                       

                      Refresh the EO in any windows server and get the output.

                       

                       

                       

                       

                       

                       

                      • 8. Re: How to run VB Script via Bladelogic extended Object
                        Yanick Girouard

                        I had already answered the same thing, even simplier. Why post a new answer with the same information?