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.
Does that make sense?
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%"
- 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.