script to trigger Machine policy or Hardware inventory action agent on SCCM clients

There are lot of tools available like SCCM client center or Collection commander or Right Click Tools etc. to trigger SCCM client agent Actions using these tools but the customer environment doesn’t have any of these tools to use and we had a requirement to run the machine policy and other actions items as well.

I have used the below script to run(ex:Machine policy and evaluation cycle or hardware inventory action etc) on a list of computers that you have supplied in notepad.txt using psexec tool.The script reset the hardware inventory action and deletes the instance before running hardware inventory.

What do you require to carry out this task: A Share folder(create one) ,Psexec tool, Vb script(below) and batch script(below).

Open a notepad,copy the below code and save as trigger_policy.vbs.

'Declare Variables
On Error Resume Next
Set sho = CreateObject("WScript.Shell")
strSystemRoot = sho.expandenvironmentstrings("%SystemRoot%")
strCurrentDir = Left(Wscript.ScriptFullName, (InstrRev(Wscript.ScriptFullName, "\") -1))
' 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")
'Reset SMS Hardware Inventory Action to force a full HW Inventory Action
sInventoryActionID = "{00000000-0000-0000-0000-000000000001}"
' Delete the specified InventoryActionStatus instance
oServices.Delete "InventoryActionStatus.InventoryActionID=""" & sInventoryActionID & """"
'Pause 3 seconds To allow the action to complete.
wscript.sleep 3000
'Run a SMS Hardware Inventory
Set cpApplet = CreateObject("CPAPPLET.CPAppletMgr")
Set actions = cpApplet.GetClientActions
For Each action In actions
If Instr(action.Name,"Hardware Inventory") > 0 Then
End If

since the above script you have created is to trigger hardware inventory action,You will have all the Actions ID given below for each.

    • Hardware Inventory – 00000000-0000-0000-0000-000000000001
    • Software Inventory – 00000000-0000-0000-0000-000000000002
    • Data Discovery – 00000000-0000-0000-0000-000000000003
    • Machine Policy Assignment Request – 00000000-0000-0000-0000-000000000021
    • Machine Policy Evaluation – 00000000-0000-0000-0000-000000000022
    • Refresh Default Management Point – 00000000-0000-0000-0000-000000000023
    • Refresh Location (AD site or Subnet) – 00000000-0000-0000-0000-000000000024
    • Software Metering Usage Reporting – 00000000-0000-0000-0000-000000000031
    • Source list Update Cycle – 00000000-0000-0000-0000-000000000032
    • Refresh proxy management point – 00000000-0000-0000-0000-000000000037
    • Cleanup policy – 00000000-0000-0000-0000-000000000040
    • Validate assignments – 00000000-0000-0000-0000-000000000042
    • Certificate Maintenance – 00000000-0000-0000-0000-000000000051
    • Branch DP Scheduled Maintenance – 00000000-0000-0000-0000-000000000061
    • Branch DP Provisioning Status Reporting – 00000000-0000-0000-0000-000000000062
    • Software Update Deployment – 00000000-0000-0000-0000-000000000108
    • State Message Upload – 00000000-0000-0000-0000-000000000111
    • State Message Cache Cleanup – 00000000-0000-0000-0000-000000000112
    • Software Update Scan – 00000000-0000-0000-0000-000000000113
    • Software Update Deployment Re-eval – 00000000-0000-0000-0000-000000000114
    • OOBS Discovery – 00000000-0000-0000-0000-000000000120

You can see all the above actions item IDs from WMI. From Run command,type wbemtest and use the name space as 'root\CCM\Policy\Machine'. It list all the classes (Dynamic or Static from WMI Repository).

Again,open notepad and copy the below code into it and save as name.bat

@Echo off
REM Initiating Hardware inventory agent action
cd d:\script
psexec @computers.txt -c \\Servername\actions\trigger_policy.vbs



Now run the batch script which you created above from either command prompt or directly from folder.

Hope it helps someone who doesn’t use the automated tools.

Have blogged the same post on

28 Responses to "script to trigger Machine policy or Hardware inventory action agent on SCCM clients"

    1. Hi Sana,
      To trigger hardware inventory using Task sequence, you can simply run wmic command ,no need of using this script.
      Trigger hinv using WMIC: WMIC /namespace:\\root\ccm path sms_client CALL TriggerSchedule "{00000000-0000-0000-0000-000000000001}" /NOINTERACTIVE


      1. Hi Eswar,

        I tried running it through command line and it did not work. It could not trigger the cycle as the client is not fully initialized. I ended up creating a scheduled task for which runs as soon as TS completes.

        Sana K

        1. have you tried looking at smsts.log, followed by inventoryagent. log? did you try this running using the cmd line manually if it works? ah.. there is no point running this cmd line during the osd as client may take some time to load policies and become fully functional. by the way,what are you trying to achieve ? why not you use script that i posted to trigger inventory or other methods instead of going through schedule task

      2. Hello Eswar,
        thank you for the nice post.
        When i try to run the command WMIC /namespace:\\root\ccm path sms_client CALL TriggerSchedule "{00000000-0000-0000-0000-000000000xxx" i get the error below:
        Description = Not found

        Any idea?

        Thank you!

          1. Hello again,
            the problem was with the MP role, uninstalling and installing back solved the problem. During it, hardware, software scan and other actions failed to run.

            Thank you for your reply.
            Take care!

  1. root\CCM\Policy\Machine' - Getting below error

    Number: 0x8004100e
    Facility: WMI
    Description: Invalid namespace

    I opened webmtest as admin. Can u pls help me

    1. have you checked if the client is successfully installed ? root\CCM\Policy\Machine is created only if the client is installed successfully .

      1. Actually Im doing it as part of client remediation. We have few inactive clients and Im trying to fix it through sccm client action tool.

        client action tool showing error like - Failed to get last HW scan date. and when I check the client logs, Inventoryagent.log also missing.

        Hence I though I will force the Hardware inventory. I used
        \\\root\ccm\invagt namespace to connect and no instances are listed there 🙁

      1. *.vbscript successfully copied to system32 on remote computer, but didn't run/delete it.
        Сan not find the file specified.

        I done this way:
        (*.bat/cmd copy,run and delete with no error by psexec -c)

        setlocal enabledelayedexpansion
        for /f %%i in (computers.txt) do (
        set stat=%%i
        timeout /T 1
        start name.bat !stat!

        psexec \\%1 -C -F \\Servername\actions\trigger_policy.bat

        WMIC /namespace:\\root\ccm\invagt path inventoryActionStatus where InventoryActionID="{00000000-0000-0000-0000-000000000001}" DELETE /NOINTERACTIVE
        WMIC /namespace:\\root\ccm PATH sms_client CALL TriggerSchedule "{00000000-0000-0000-0000-000000000001}" /NOINTERACTIVE

        Used this script for Full Hardware Inventory on list of PC's after sortmif.exe
        Thank you.

        1. have you checked the logs if the policy trigger happened or not ?
          i just created a 2 scripts one to open notepad on remote computers and other to run the psexec tool.
          batch script 1:psexec @computers.txt -c \\Computername\test\test-psexec1.bat
          batch script 2:notepad.exe
          just run script 1 ,have a look at the remote computer if the notepad opened or not ?

          1. Which logs do you mean?

            Essence of the question:
            Psexec tool with key "-c" do not work with vbs scripts.
            You used it in your post:
            psexec @computers.txt -c \\Servername\actions\trigger_policy.vbs
            With batch scripts, psexec tool work fine. So notepad opened, and my batch scripts also working without problem.

            1. ok,i did some tests using -c for vbscript but it doesn't work using -c command though Microsoft document says it .Though my blog post is very old around 3 years and am sure i ran it for multiple times to initiate the policies.
              To replace this ,i used -s instead of -c for vbscript to run remotely,it works good.
              can you try this cmd line :PsExec.exe -S @computers.txt cscript.exe "\\servername\sharename\script.vbs"

            2. ok,i did some tests using -c for vbscript but it doesn't work using -c command though Microsoft document says it .Though my blog post is very old around 3 years and am sure i ran it for multiple times to initiate the policies.
              To replace this ,i used -s instead of -c for vbscript to run remotely,it works good.
              can you try this cmd line :PsExec.exe -S @computers.txt cscript.exe "\\PCname\sharename\script.vbs"

  2. Great post. I used to be checking continuously this blog and I am impressed! Very useful information specially the last part 🙂 I deal with such info much. I was seeking this certain info for a very lengthy time. Thanks and best of luck.


Leave a Reply