1

When creating standard program for SCCM in the GUI, there is this lovely little checkbox to "Always run this program first":

Screenshot of Program Requirements

I cannot find a way to check this box with PowerShell. Does anyone know if this is even possible?

For those that want more detail:

I have a package that has four different programs in it. I want to execute each of these programs in a specific order. I was able to add the Dependent Program using a method I found here, but it only adds the program, it does not check the "Always run this program first" box. I compared the object I am creating with New-CMProgram, with one I created manually with the GUI that has the box checked, but they are the exact same as far as the object and properties go.

I am running the latest version of SCCM: Version 1802

Community
  • 1
  • 1
smiler07
  • 107
  • 2
  • 5
  • This is more of an infrastructure administration question than it is a programming question, so [ServerFault](https://serverfault.com/) would be a better place for it. – Ansgar Wiechers Aug 17 '18 at 08:13
  • I think he does not really want to manipulate the gui but programatically create a program in powershell and just included the screenshot to make clear where his script differs from the manual approach – Syberdoor Aug 17 '18 at 09:59

1 Answers1

2

This should be part of the ProgramFlags property, which is basically a bitmask for several options that unfortunately don't have their own explicit property. It is a common concept with all of the old Package/Program type objects which is a little annyoing to handle. The program flags are described in detail in the description of the SMS_Program WMI class where it says:

0x00000080 (7): RUN_DEPENDANT_ALWAYS. If set, this program's immediate dependent should always be run.

so basically you have to flip the 7th bit to turn this on or off. Now I don't know whether you are familiar with this concepts of bitmasks, it basically means viewing an integer in it's binary form and assigning each position a boolean meaning to flip it but storing it as the final number that is the "sum" of all the bits.

So in your case this would mean you ProgramFlags should be something like 2282791936 (these numbers can vary dependent on you other options of course but they should change when you change the setting) when you don't have the box checked and 2282792064 if you have it checked. (The 0x80 mentioned in the class description is 128 decimal so the one number should be 128 higher than the other)

Now the "official" way to program this would of course be to gather all the flags you want from the description and build your own number and work with that, but I found that some of them are oddly dependent and some hard to understand, so in cases like yours where I know exactly what I want from a GUI perspective I always just created a program as needed, exported the value and hard coded it in my script. You can do this the same way as you did with the dependent program:

$p = Get-CMProgram -PackageName "packagename" -ProgramName "programname"
$p.ProgramFlags = <your flags>
$p.put()
Syberdoor
  • 2,521
  • 1
  • 11
  • 14
  • This worked perfectly! You're a genius! I was able to Export the ProgramFlags from my current program and set them using the method described above! A followup question I have: If I set the program Flags value to the exact settings I want, do I also need to also set other parameters such as 'ProgramRunType" or "RunMode", or do those get set with the program flags? – smiler07 Aug 17 '18 at 17:07
  • It's a little hard to say for each value but a good estimate is: If you don't see a custom parameter in a the object you get from Get-CMProgram it is probably part of ProgramFlags. In this case e.g. runtype is either bit 14 (=only when user logged in) or 17 (=only when user not logged in) or none of them (=all users) I'd say. If you export the value all the settings that programfiles cover are set in the way they were in the program you exported from. There is no such thing as an "empty" setting this way. In case you are unsure just experiment, change the values and check the gui again. – Syberdoor Aug 18 '18 at 11:53