Close Menu
    Facebook X (Twitter) Instagram
    Sunday, October 12
    X (Twitter) LinkedIn Reddit RSS
    All about Endpoint Management
    • Home
    All about Endpoint Management
    Home»SCCM 2007»script to trigger Machine policy or Hardware inventory action agent on SCCM clients

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

    Eswar KonetiBy Eswar KonetiJanuary 11, 8:40 pm3 Mins Read SCCM 2007 13,270 Views
    Share
    Facebook Twitter LinkedIn Reddit

    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
    action.PerformAction
    End If
    Next

    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
    d:
    psexec @computers.txt -c \\Servername\actions\trigger_policy.vbs

    Exit

     

    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 http://wmug.co.uk/blogs/eskonr/archive/2011/01/12/how_2D00_to_2D00_trigger_2D00_sccm_2D00_machine_2D00_policy_2D00_or_2D00_hardware_2D00_inventory_2D00_action_2D00_agent_2D00_on_2D00_remote_2D00_computers.aspx

    configmgr Configmgr 2007 hardware agent inventory agent Inventory Agent actions machine policy remote run machine policy SCCM SCCM 2012 sccm client script trigger policy agents VB Script
    Share. Twitter LinkedIn Email Facebook Reddit

    Related Posts

    SCCM SQL Report – Compare Installed Apps on TWO Different Computers

    July 13, 10:35 am

    Optimize Your Intune Workflow with a Powerful Browser Extension

    March 22, 10:39 am

    Migrate Microsoft 365 Updates from SCCM/MECM to Intune for Co-Managed Devices

    February 11, 9:50 pm

    29 Comments

    1. Sana Kosanam on April 23, 2016 7:12 AM

      Hi Eswar,

      Can I run it from Task Sequence(In last possible step of TS)?

      Thanks
      Sana

      Reply
      • Eswar Koneti on April 23, 2016 10:47 PM

        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

        Thanks,
        Eswar

        Reply
        • Sana Kosanam on April 28, 2016 2:06 AM

          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.

          Thanks
          Sana K

          Reply
          • Eswar Koneti on April 28, 2016 6:25 PM

            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

            Reply
        • Panos on September 1, 2016 8:46 PM

          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:
          ERROR:
          Description = Not found

          Any idea?

          Thank you!
          Panos

          Reply
          • Eswar Koneti on September 4, 2016 10:19 AM

            Looks like the scheduleID what you are using could not found in wmi. Check if the Id exists what you are using. What Id is that?

            Reply
            • Panos on September 6, 2016 7:59 PM

              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!
              Panos.

              Reply
    2. Shridevi on August 28, 2015 5:25 PM

      sorry for typo. Its \\\root\ccm\invagt

      Reply
      • Eswar Koneti on November 16, 2015 10:27 AM

        Check for SCCM client installation is succeded or not ? without SCCM client,you wont see any instances in wmi for Client.

        Reply
    3. Shridevi on August 26, 2015 10:53 PM

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

      Number: 0x8004100e
      Facility: WMI
      Description: Invalid namespace

      I opened webmtest as admin. Can u pls help me

      Reply
      • Eswar Koneti on August 28, 2015 8:33 AM

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

        Reply
        • Shridevi on August 28, 2015 5:18 PM

          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 🙁

          Reply
          • Eswar Koneti on November 16, 2015 10:26 AM

            seems like client did not install correctly.if client is not installed,you will not see any instances in wmi.

            Reply
    4. Arkadii on August 21, 2015 5:03 PM

      Thank you!
      It's work fine.

      Reply
    5. Arkadii on August 18, 2015 10:37 PM

      Hi all!
      psexec @computers.txt -c \\Servername\actions\trigger_policy.vbs

      don't work!

      Reply
      • Eswar Koneti on August 19, 2015 3:11 PM

        what is the error you get when you run psexec ? it works good for me.did you share the folder that have these files in ?

        Reply
        • Arkadii on August 19, 2015 10:12 PM

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

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

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

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

          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
          http://eskonr.com/2010/01/inventory-data-loader-issues-in-sccm-inboxes/
          Thank you.

          Reply
          • Eswar Koneti on August 20, 2015 8:55 AM

            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 ?

            Reply
            • Arkadii on August 20, 2015 4:10 PM

              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.

              Reply
              • Eswar Koneti on August 21, 2015 1:01 PM

                ok,i did some tests using -c for vbscript but it doesn't work using -c command though Microsoft document says it https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx?f=255&MSPPError=-2147217396 .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"

              • Eswar Koneti on August 21, 2015 1:01 PM

                ok,i did some tests using -c for vbscript but it doesn't work using -c command though Microsoft document says it https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx?f=255&MSPPError=-2147217396 .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"

    6. Arkadii on August 18, 2015 8:16 PM

      I have a problem with name.bat.
      psexec -c don't work with *.vbs

      http://forum.sysinternals.com/topic7879.html

      Thanks for help.

      Reply
    7. Semedar on October 9, 2013 2:09 AM

      Awesome, thanks for the list of all the action ID's.

      Reply
    8. MattH on May 7, 2013 10:06 PM

      Does this work with ConfigMgr 2012?

      Reply
      • Eswar Koneti on May 8, 2013 11:11 AM

        Yes,I tried for hardware inventory.it works !

        Reply
    9. 0day on November 12, 2011 12:35 PM

      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.

      Reply
    10. Marcus on August 2, 2011 2:03 AM

      Does this work for you on Win7 x64? I'm not having any luck.
      (Access denied)

      Reply
      • Eswar Koneti on August 2, 2011 12:06 PM

        Access Denied --do you have sufficient rights on the target computer ?
        what does the error message says ?

        Reply

    Leave a ReplyCancel reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Sign Up

    Get email notifications for new posts.

    Author

    I’m Eswar Koneti ,a tech enthusiast, security advocate, and your guide to Microsoft Intune and Modern Device Management. My goal? To turn complex tech into actionable insights for a streamlined management experience. Let’s navigate this journey together!

    Support

    Awards

    Archives

    © Copyright 2009-2025 Eswar Koneti, All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.