Add or Remove Multiple Application Deployments in SCCM using Powershell

How to add or remove multiple sccm application deployments

Last updated on April 1st, 2023 at 06:23 pm

Read Time:4 Minute, 38 Second

Problem Scenario

When using SCCM, you may find that you want to either add or remove application deployments based on what administrative categories each application has assigned.

As an example, we had a number of applications for the Marketing department that were only distributed to a Marketing collection we had set up with only Marketing devices in the collection. However, we were asked to remove these applications from Marketing and make them available to R&D instead due to a merger of departments.

So the task in front of us was to delete the application deployments for each application under the Marketing administrative category and then deploy the applications with the R&D administrative category.

Seems simple but if you are an experienced SCCM admin, you will know that you can’t just CTRL+A and hit the delete button for deployments within the SCCM console. Nor can you deployment multiple applications at the same time, even if it is to the same collection.

Administrative Categories

We needed a quick solution as none of us wanted to sit there right-click deleting deployments for days, so as usual, Powershell is your friend. But before we get to that bit, you can utilise the Administrative Categories wisely to deploy and remove deployments.

All our existing Marketing applications already have the Marketing administrative categories applied to them. But we now want to also add the R&D Administrative Category to these applications.

If you need to set or remove Administrative Categories on your applications, you can select all, right-click and then click on Categories to do this.

We now have our applications with both Marketing and R&D Administrative Categories setup.

Powershell

We will now add the application deployments to the applications marked as R&D in their Administrative Categories. To do this, we will use the SCCM Powershell applets available to us. To do this, open your SCCM Console and at the very top left of the console is a blue button with a white drop-down arrow:

Add or Remove Multiple Application Deployments in SCCM using Powershell 1
SCCM Console Drop Down Menu

Click this and then select the option – Connect via Windows PowerShell ISE:

Add or Remove Multiple Application Deployments in SCCM using Powershell 2
SCCM Console Powershell Menu

This will open up the Powershell ISE console and will also pre-populate a PS1 file which you should run to enable the required SCCM Powershell modules.

Add Multiple Application Deployments

Now that you have your SCCM Powershell modules loaded, you can run the commands required to add the deployments to multiple applications.

This is the command that you will need to run, but ensure that you edit it first to suit your requirements:

(Get-CMApplication | Where-object { ($_.LocalizedCategoryInstanceNames -Contains "R&D") -and ($_.IsExpired -ne "True") } | Select LocalizedDisplayName | Sort-Object) | % { New-CMApplicationDeployment -CollectionName "All RD Devices" -Name "$($_.LocalizedDisplayName)" -DeployAction Install -DeployPurpose Available -UserNotification DisplaySoftwareCenterOnly -EnableMomAlert $True -RaiseMomAlertsOnFailure $True -PersistOnWriteFilterDevice $True } -Verbose

The bold areas are what you should at least be looking to amend.

  • R&D = The new Administrative Category
  • All RD Devices = The Device Collection to deploy to.

Run this command and it will go through and find all applications with the Administrative Category of R&D and it will add the deployment to each of these applications to All RD Devices.

It can take some time depending on how many applications you have and may even look like it has frozen, but it has not, give it time to complete.

Add Multiple Application Deployments with Approval Required

You may want to deploy your packaged application to a collection but with the requirement for it to be approved before deployment. You can easily do this as well simply by adding the following to your Powershell code:

  • -ApprovalRequired $true

Add this just after your DeployPurpose Available and when you run it, it will add the requirement for the request to be approved before releasing for deployment.

The full Powershell code example is below:

(Get-CMApplication | Where-object { ($_.LocalizedCategoryInstanceNames -Contains "Office Software") -and ($_.IsExpired -ne "True") } | Select LocalizedDisplayName | Sort-Object) | % { New-CMApplicationDeployment -CollectionName "All Apps Requiring Approval" -Name "$($_.LocalizedDisplayName)" -DeployAction Install -DeployPurpose Available -ApprovalRequired $true -UserNotification DisplaySoftwareCenterOnly -EnableMomAlert $True -RaiseMomAlertsOnFailure $True -PersistOnWriteFilterDevice $True } -Verbose

Again remembering to change the Administrative Category and the deployment that you want to remove:

  • Office Software = Administrative Category Applications to remove the deployment for
  • All Apps Requiring Approval = The deployment collection to be removed

Remove Multiple Application Deployments

In our scenario, we now want to remove the deployment for all applications with Marketing as their Administrative Category. To do this, we need to run the following command in the Powershell console:

(Get-CMApplication | Where-object { ($_.LocalizedCategoryInstanceNames -Contains "Marketing") -and ($_.IsExpired -ne "True") } | Select LocalizedDisplayName | Sort-Object) | % { Remove-CMApplicationDeployment -CollectionName "All Marketing Users" -Name "$($_.LocalizedDisplayName)"} -Confirm -Verbose

Again remembering to change the Administrative Category and the deployment that you want to remove:

  • Marketing = Administrative Category Applications to remove the deployment for
  • All Marketing Users = The deployment collection to be removed

Run this command and again it may take some time depending on your number of applications, but when it completes, you will see that all the All Marketing Users collection deployments have now been removed.

Conclusion

Nobody wants to waste time right-clicking and selecting delete for a number of applications, so Powershell is the best tool to use to take care of it all for you.

You can amend these add and remove Powershell commands to do all sorts, just remember that all it is really doing is searching for your criteria, to begin with, then executing the command you are telling it to in the second phase.

Click to rate this post!
[Total: 1 Average: 5]

Free Subscription

If you want to be notified when we post more quality guides like this one, sign up to our free subscription service and you will receive an email when a new post is live.

Join 441 other subscribers.

No need to worry, we will not be filling your inbox with spam and you can unsubscribe anytime you like.


Leave us a message...

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