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.vbsExit
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
29 Comments
Hi Eswar,
Can I run it from Task Sequence(In last possible step of TS)?
Thanks
Sana
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
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
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
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
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?
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.
sorry for typo. Its \\\root\ccm\invagt
Check for SCCM client installation is succeded or not ? without SCCM client,you wont see any instances in wmi for Client.
root\CCM\Policy\Machine' - Getting below error
Number: 0x8004100e
Facility: WMI
Description: Invalid namespace
I opened webmtest as admin. Can u pls help me
have you checked if the client is successfully installed ? root\CCM\Policy\Machine is created only if the client is installed successfully .
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 🙁
seems like client did not install correctly.if client is not installed,you will not see any instances in wmi.
Thank you!
It's work fine.
Hi all!
psexec @computers.txt -c \\Servername\actions\trigger_policy.vbs
don't work!
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 ?
*.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.
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 ?
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.
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"
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"
I have a problem with name.bat.
psexec -c don't work with *.vbs
http://forum.sysinternals.com/topic7879.html
Thanks for help.
Awesome, thanks for the list of all the action ID's.
Does this work with ConfigMgr 2012?
Yes,I tried for hardware inventory.it works !
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.
Does this work for you on Win7 x64? I'm not having any luck.
(Access denied)
Access Denied --do you have sufficient rights on the target computer ?
what does the error message says ?