Forum Discussion
Script for SCCM Help please
- Feb 28, 2022
This link will help you to add a device to a collection during your OS deployment via Task Sequence.
Add a Device to a Collection during a Task Sequence (smsagent.blog)
After you add that step your task sequence, You can add a WMI query for define HP EliteBooks on options tab.
I think that will solve your problem.
If you have to add computers manually to collection it seems your query is wrong. When your query is correct you won't need any script for move computers to the collection. They will move automatically.
Let's fix it. Could you check that below :
1. Right click a computer in your collection and select start -> Resource Explorer.
2. Find to Hardware -> Computer System -> Model
If there is HP EliteBook 830 G8 and you want to computers which model is HP EliteBook 830 G8:
select * from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.Model = "HP EliteBook 830 G8"
If you want to all HP EliteBook not only 830 G8:
select * from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.Model like "%HP EliteBook%"
- Mar 02, 2022You're welcome 🙂
- ToptechnicalSolutionsMar 02, 2022Copper Contributoryou are amazing thanks for your help on this.
- Mar 02, 2022All machines, whether HP Elitebook or not, are added to the All Desktop collection. Only computers with HP EliteBooks are added to the HP Elitebook collection.
- ToptechnicalSolutionsMar 02, 2022Copper ContributorBut for new machines being built as new machines that are not HP machines will they go into the main "All desktop" collection and if it is a HP elitebook and we build a new one it will go into the HP elitebook collection?
- Mar 02, 2022Any machine that is already a SCCM agent will be in the collection of all desktop and server clients. However, if the model is HP EliteBook 830 G8, it will be in both all desktop and server clients and HP ELiteBook 380 G8 collections.
- ToptechnicalSolutionsMar 02, 2022Copper ContributorYeah I know I just put our server but I will change that.
But I just wanted to confirm that when I add this run command line and the option tab then when I build any machine it will go into the “all desktop and server clients” but if it’s a HP elite book it will go into the HP elitebook 830 G8 collection - Mar 02, 2022You didn't write the server name in the Properties section.
- ToptechnicalSolutionsMar 01, 2022Copper ContributorSo I would literally add a run command line
cmd /c powershell.exe -Command "&{$Me = $Env:COMPUTERNAME; Invoke-command -Computername OURSERVER -ArgumentList $Me -scriptblock {param($Me)Import-Module ConfigurationManager; cd IP1:; $Computer = Get-CMDevice -Name $Me; if ($Computer){Add-CMDeviceCollectionDirectMembershipRule -CollectionName 'HP Elitebook 830 G8' -Resource $Computer}}}"
And add the options tab
SELECT * FROM Win32_ComputerSystem WHERE Model LIKE "%HP EliteBook 830 G8%"
Then when I build any machine it will go into the “all desktop and server clients” but if it’s a HP elite book it will go into the HP elitebook 830 G8 collection? - Mar 01, 2022
- ToptechnicalSolutionsMar 01, 2022Copper ContributorOh ok so as we only have one build process and 1 task sequence, if i add this code with the options part it will recognise that the option that this is a HP and move to the HP Elitebook Collection but all others will stay in the normal All Desktop and Server Clients?
Or would it be easier to create another Task sequence just for the HP ones? - Mar 01, 2022
You don't need this configuration for "All Desktop and Server Clients". When you deploy OS via Task Sequence, computers will install SCCM agent automatically. Also computers will add to "All Desktop and Server Clients" collection automatically. So you don't need that task sequence step for this collection.
You need this configuration for HP EliteBook 830 G8. You can add Task Sequence step for that collection which name "HP EliteBook 830 G8".
Properties tab:
cmd /c powershell.exe -Command "&{$Me = $Env:COMPUTERNAME; Invoke-command -Computername YOURSITESERVER -ArgumentList $Me -scriptblock {param($Me)Import-Module ConfigurationManager; cd YOURSITECODE:; $Computer = Get-CMDevice -Name $Me; if ($Computer){Add-CMDeviceCollectionDirectMembershipRule -CollectionName 'HP EliteBook 830 G8' -Resource $Computer}}}"
- YOURSITESERVER (ConfigMgr Site Server Name, or anywhere with the ConfigMgr Console / Cmdlets installed)
- YOURSITECODE (Site Code)
- Change the “Run this step as…” account to an account that has the necessary permissions on the site server
Options Tab:
Add Condition -> Query WMI
WQL Query:
SELECT * FROM Win32_ComputerSystem WHERE Model LIKE "%HP EliteBook 830 G8%"
- ToptechnicalSolutionsMar 01, 2022Copper ContributorSo just to clarify, if i use the code in the standard task sequence we have for building machinesand i change the CAPS areas for server, site and colelctionname (the standard collection name is "All Desktop and Server Clients")
cmd /c powershell.exe -Command "&{$Me = $Env:COMPUTERNAME; Invoke-command -Computername OURSERVER -ArgumentList $Me -scriptblock {param($Me)Import-Module ConfigurationManager; cd IP1:; $Computer = Get-CMDevice -Name $Me; if ($Computer){Add-CMDeviceCollectionDirectMembershipRule -CollectionName 'All Desktop and Server Clients' -Resource $Computer}}}"
this will be my normal build for all models of machines then i add the option tab
SELECT * FROM Win32_ComputerSystem WHERE Model LIKE "%HP EliteBook%"
How will this move the HP machines to the other collection called "HP EliteBook 830 G8"?
Sorry for so many questions. - Mar 01, 2022
You can add a Run Commandline step to your task sequence
Properties Tab:
Paste the code below into the Command line window
cmd /c powershell.exe -Command "&{$Me = $Env:COMPUTERNAME; Invoke-command -Computername MYSITESERVER -ArgumentList $Me -scriptblock {param($Me)Import-Module ConfigurationManager; cd ABC:; $Computer = Get-CMDevice -Name $Me; if ($Computer){Add-CMDeviceCollectionDirectMembershipRule -CollectionName 'COLLECTIONNAME' -Resource $Computer}}}"
- MYSITESERVER (ConfigMgr Site Server Name, or anywhere with the ConfigMgr Console / Cmdlets installed)
- ABC (Site Code)
- COLLECTIONNAME (The name of the target collection)
- Change the “Run this step as…” account to an account that has the necessary permissions on the site server
Options Tab:
Add Condition -> Query WMI
WQL Query:
SELECT * FROM Win32_ComputerSystem WHERE Model LIKE "%HP EliteBook%"
- ToptechnicalSolutionsMar 01, 2022Copper ContributorThanks, I will read through. I really want to have a script like this that runs as part of task sequence but i want it to see the model instead and if it is a HP eltebook i can then use the add-device to the collection. Would you know what i could use to do that? I know that wmic csproduct get name will show the model which then i want it to use the info to move.
Does that make sense? - Feb 28, 2022
This link will help you to add a device to a collection during your OS deployment via Task Sequence.
Add a Device to a Collection during a Task Sequence (smsagent.blog)
After you add that step your task sequence, You can add a WMI query for define HP EliteBooks on options tab.
I think that will solve your problem.
- ToptechnicalSolutionsFeb 28, 2022Copper ContributorThe issue we have is it can take upto 7 days to get the inventory which can cause build slowness,.
- ToptechnicalSolutionsFeb 28, 2022Copper ContributorYes we can do this but this is the reason why we wanted to have a variable put into the build process to say if this is a HP elitebook then add the variable to the client which would then we can grab anything with this variable and move to the collection. so we wouldnt have to do this manual process.
- Feb 28, 2022
You can trigger Collect Hardware Inventory manually that like below.
Right click the colleciton -> Client Notfiication -> Collect hardware Inventory
- ToptechnicalSolutionsFeb 28, 2022Copper ContributorYes we have the same settings as you above but for some reason the machines are taken sometimes days to inventory to go into the relevant collection.
- Feb 28, 2022
It doesn't matter 🙂
You can configure Hardware Inventory Schedule on Client Settings.
Administration -> Client Settings -> Right click to Default Client Settings -> Select Properties
Hardware Inventory -> Schedule...
- ToptechnicalSolutionsFeb 28, 2022Copper ContributorI think i got a little confused. Bascically the query works but we have to wait for the Hardware Inventory Cycle to happen which is taken so long we are waiting for this to happen then the machine is moving but is there anyway to make this happen quicker or to make this work quicker so we cna deploy the collection info.
Sorry for the confusion - ToptechnicalSolutionsFeb 28, 2022Copper ContributorWe dont have a query setup yet to move the machoines to this collection we have done this manually at the moment so i need to work out how we set this query up to allow this to happen.
- Feb 28, 2022
Your query for HP EliteBook 830 G8 NoteBook PC seems correct for HP EliteBook G8 Collection. So you don't need a script for new HP ElifteBook 830 G8 NoteBook PCs. They will move automatically in your HP EliteBook G8 collection when your OS installation completed and installed SCCM Client Agent on PCs. You don't need any action for moving new PCs into the collection.
When you remove PCs which manually added to the collection and right click to collection select update membership, the PCs will add to the collection automatically. Also new PCs which is same model will.
- ToptechnicalSolutionsFeb 28, 2022Copper Contributor
Hi hasanemresatilmis I have checked the resource editor
This is a PC within the collection So i want to move any computer which is a HP elitebook when we build them into this collection. Where would I add this query? Do i add it as part of the build process?
I appreciate your help on this.