none
Выполнить скрипт на клиенте RRS feed

  • Общие обсуждения

  • Привет

    ну и замаялся я с переинвентаризацией.

    Нашёл скриптик позволяющий скинуть кеш на клиенте. (см. ниже)

    Создал пекедж с программой.

    Программа выглядит так:

    wscript.exe SMS_Client_Actions.vbs ResetInventoryCache {00000000-0000-0000-0000-000000000001}  Pause 2000  KickoffClientAction "Hardware Inventory Collection Cycle"

    скинул в папку \\kv-sms-02-sql\download\xcopy сам скрипт и wscript.exe

    указал, что запускать из даной папки.

    Создал коллекцию и адвертайзмент. Адвертайзмент отработал. А вот инфы в базе не добавилос.

    Может я неправильно скрипт запускаю?

    Тут написано, что:

    So do NOT launch the
     'script from the Distrobution point, ALWAYS download the script to the system and launch locally.

    Сейчас переделал пакет чтобы запускался на клиенте.

    Посмотрим. 

     

      сам скрипт:

    'Script Function;
     'This script takes command lines and executes SMS client commands one after another.

    'Use ****WARNING****;
     'Make sure that the script is set to download and launch on the local system.
     'The script creates a log file in the folder where the script is located.  So do NOT launch the
     'script from the Distrobution point, ALWAYS download the script to the system and launch locally.

    'Input command examples;
     'Delete the current software inventory data, pause for 2 seconds, initiate Software Inventory.
     'This in effect sends a full software inventory.
    'ResetInventoryCache {00000000-0000-0000-0000-000000000002}  Pause 2000  KickoffClientAction "Software Inventory Collection Cycle"

     'Delete the current Hardware inventory data, pause for 2 seconds, initiate Hardware Inventory.
     'This in effect sends a full hardware inventory.
    'ResetInventoryCache {00000000-0000-0000-0000-000000000001}  Pause 2000  KickoffClientAction "Hardware Inventory Collection Cycle"

     'Launch Software and Hardware Inventory processes sending in difference data since last inventory operation.
    'KickoffClientAction "Software Inventory Collection Cycle"  KickoffClientAction "Hardware Inventory Collection Cycle"

     'Launch Hardware inventory data with difference data since last inventory operation.
    'KickoffClientAction "Hardware Inventory Collection Cycle"

     'Launch Software inventory data with difference data since last inventory operation.
    'KickoffClientAction "Software Inventory Collection Cycle"

    'Return;
     '0 if there was no errors.
     '1639 if the commands were not correct on the command line
     '22 if the error was < 0 or > 14080
     'The script creates a log in the folder where the script is located.

    Option Explicit

    Dim ReturnError

    on error resume next

    ReturnError = Main
    wscript.quit ( ReturnError )

    Function Main()

     Dim CommandError, CommandLine, CommandToLaunch, CommandData, CommandLineNumber
     Dim FirstQuote, SecondQuote, QuotedData

     on error resume next

     FileAddLineToLogFile "Beginning " & wscript.scriptfullname

     CommandError = 0

     if WScript.Arguments.Count = 0 then
      'incorrect command lines used. Return Invalid command line argument.
      FileAddLineToLogFile "There are no command lines, unable to perform any functions without a command."
      Main = 1639
      exit Function
     end if

     if WScript.Arguments.Count < 1 then
      'insufficient amount of command lines used. Return Invalid command line argument.
      FileAddLineToLogFile "There not enough command lines, check command syntax."
      Main = 1639
      exit Function
     end if

     'retrieve command lines
     Set CommandLine = WScript.Arguments
     FileAddLineToLogFile "Command line count = " & CommandLine.Count

     'Step through each command
     For CommandLineNumber = 0 to CommandLine.Count - 1 step 2
      FileAddLineToLogFile "Processing line = " & CommandLineNumber

      'retrieve the command
      CommandToLaunch = trim ( CommandLine( CommandLineNumber ) )
      if err.number = 0 then
       FileAddLineToLogFile "CommandToLaunch = " & CommandToLaunch
      else
       FileAddLineToLogFile "There are not enough command lines, check command syntax."
       Main = 1639
       exit Function
      end if

      'retrieve the command data
      CommandData = trim ( CommandLine( CommandLineNumber + 1 ) )
      if err.number = 0 then
       FileAddLineToLogFile "CommandData = " & CommandData
      else
       FileAddLineToLogFile "There are not enough command lines after '" & CommandToLaunch & "', check command syntax."
       Main = 1639
       exit Function
      end if

      'run the command
      Select Case ucase (CommandToLaunch)
       Case "RESETINVENTORYCACHE"
        if CommandData = "" then
         FileAddLineToLogFile "ResetInventoryCache requires options, there are none."
         CommandError = 1639
        else
         FileAddLineToLogFile "ResetInventoryCache with option of '" & CommandData & "'"
         err.Clear
         ResetInventoryCache CommandData
         if err.number <> 0 then
          CommandError = err.number
          FileAddLineToLogFile "ResetInventoryCache caused error " & err.number & " = '" & err.Description & "'"
          err.Clear
         end if 
        End if

       Case "KICKOFFCLIENTACTION"
        if CommandData = "" then
         FileAddLineToLogFile "KickoffClientAction requires options, there are none."
         CommandError = 1639
        else
         FileAddLineToLogFile "KickoffClientAction with option of '" & CommandData & "'"
         err.Clear
         KickoffClientAction CommandData
         if err.number <> 0 then
          CommandError = err.number
          FileAddLineToLogFile "ResetInventoryCache caused error " & err.number & " = '" & err.Description & "'"
          err.Clear
         end if 
        End if

       Case "PAUSE"
        if CommandData = "" then
         FileAddLineToLogFile "Pause requires options, there are none."
         CommandError = 1639
        else
         FileAddLineToLogFile "Pause with option of '" & CommandData & "'"
         wscript.sleep (CommandData)
        End if

       Case else
        FileAddLineToLogFile "Unknown command = " & CommandToLaunch
        CommandError = 1639

      End Select
     Next

     if CommandError > 14080 or CommandError < 0 then
      FileAddLineToLogFile "Error is out of bounds, returning error 22 instead of " & CommandError
      CommandError = 22
     end if

     Main = CommandError

    End Function


    Sub FileAddLineToLogFile (DataToAdd)
     'Function
      'Add a log entry to where the current script is located with extention of .log
     'Input
      'Data to be added to the log
     'Output
      'Log file in script directory contains the new log entry

     Const ForAppending = 8
     Dim objFSO, objLogFile, LogFileName
     Set objFSO = CreateObject("Scripting.FileSystemObject")
     LogFileName = wscript.scriptfullname & ".log"
     Set objLogFile = objFSO.OpenTextFile ( LogFileName, ForAppending, True)
     'Write the Data
     objLogFile.WriteLine Date & " " & Time & " " & DataToAdd
     'Close the file
     objLogFile.Close
    End Sub

     

    ' *******************************************************************
    ' ResetInventoryCache() - This sub will reset the inventory cache for the specified inventory action
    ' *******************************************************************
    Sub ResetInventoryCache(sInventoryActionID)

     ' Get a connection to the "root\ccm\invagt" namespace (where the Inventory agent lives)
     Dim oLocator
     Set oLocator = CreateObject("WbemScripting.SWbemLocator")
     Dim oServices
     Set oServices = oLocator.ConnectServer( , "root\ccm\invagt")
     
     ' Delete the specified InventoryActionStatus instance
     oServices.Delete "InventoryActionStatus.InventoryActionID=""" & sInventoryActionID & """"

    End Sub

    ' *******************************************************************
    ' KickoffClientAction() - This sub will kickoff the specified client action
    ' *******************************************************************
    Sub KickoffClientAction(sActionName)

     ' Create a CPAppletMgr instance
     Dim oCPAppletMgr
     Set oCPAppletMgr = CreateObject("CPApplet.CPAppletMgr")

     ' Get the available ClientActions
     Dim oClientActions
     set oClientActions = oCPAppletMgr.GetClientActions()

     ' Loop through the available client actions
     Dim oClientAction
     For Each oClientAction In oClientActions
     
      ' Is this the action we want to kickoff?
      If oClientAction.Name = sActionName Then
      
       ' Kickoff the action
       oClientAction.PerformAction      
      End If
     Next

    End Sub
    'CRC:4458313852

     

    22 июня 2007 г. 9:32