Create a large number of applications, deployment types, deploy them to a collection and trigger machine policy receive cycle with a PowerShell script

Here is a sample on how to create a  large number of applications , the deployment types, deploy the apps to a collection and refresh policy on those clients (for testing purposes)

 

# Import CM module

Import-Module -Name “$(split-path $Env:SMS_ADMIN_UI_PATH)\ConfigurationManager.psd1”

#Set the COnfig Mgr path (site code). e.g.

Set-Location -Path R2S:

 

#Use a name basis for the appllications

$appname= “TestApp”

 

#create a loop with the needed number of steps (in this sample 500)

for($i=1

$i -le 500

$i++)

{

#edit the name for the current step in the loop to have the application names different e.g. TestApp1, TestApp2…TestApp500

$appnamef= $appname +  $i

#create a new Application

New-CMApplication -Name $appnamef -Description “TestApp created ” -SoftwareVersion “1.51” -AutoInstall $true

 

#Add the Deployment type automatically from the MSI

Add-CMDeploymentType -ApplicationName $appnamef -InstallationFileLocation “\\sourceshare\Sources\Apps\SomeApp.msi” -MsiInstaller -AutoIdentifyFromInstallationFile -ForceForUnknownPublisher $true -InstallationBehaviorType InstallForSystem

 

#Distribute the Content to the DP Group

Start-CMContentDistribution -ApplicationName $appnamef -DistributionPointName “DPName” -Verbose

}

 

#start the Deployment

#a loop with the same number of steps as applications created

for($i=1

$i -le 500

$i++)

{

#edit the name for the current step in the loop to have the application names matching the ones above

$appnamef= $appname +  $i

#create a deployment for the curent step/ app in the loop

Start-CMApplicationDeployment -CollectionName “Test Deploy” -Name  $appnamef -DeployAction Install -DeployPurpose Available -UserNotification DisplayAll -AvaliableDate (get-date) -AvaliableTime (get-date) -TimeBaseOn LocalTime  -Verbose

}

 

#refresh the Machine Policy on the Members of the Collection

Invoke-CMClientNotification -DeviceCollectionName “Test Deploy” -NotificationType RequestMachinePolicyNow -Verbose

 

 

#Run the Deployment Summarization

Invoke-CMDeploymentSummarization -CollectionName “Test Deploy” -Verbose

Leave a Reply

Your email address will not be published. Required fields are marked *