Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
function Schedule-SCCMPackageDeployment
requires \\spivsccm01\packages mounted as p Drive
[CmdletBinding(ConfirmImpact = 'None')]
[Parameter(Mandatory = $true,
HelpMessage = 'List of Computers')]
$packageName = "Microsoft Office 2016 Upgrade 32bit - Home Office"
Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" # Import the ConfigurationManager.psd1 module
Set-Location "HMN:" # Set the current location to be the site code.
$CollectionName = "test powershell"
If (Get-CMCollection -Name $CollectionName){ #if colleciton already exists delete it
Remove-CMCollection -Id (Get-CMCollection -Name $CollectionName).CollectionID -Force
$NewCollection = New-CMDeviceCollection -Name "test powershell" -LimitingCollectionName "All Systems"
Move-CMObject -FolderPath "HMN:\DeviceCollection\PKG TEST Collections\Test Collections\Nathan" -InputObject $NewCollection
foreach ($Comp in $computers){
$Device = Get-CMDevice -Name $Comp
$DeviceID = $Device.ResourceID
Add-CMDeviceCollectionDirectMembershipRule -CollectionName $NewCollection.Name -ResourceId "$DeviceID"
$date = Get-Date
$allowUsersRunIndependently = $true
$deploymentAvailableTime = $date.AddMinutes(-30)
$deviceProgramName = "Scheduled Reboot"
$packageName = "Microsoft Office 2016 Upgrade 32bit - Home Office"
$deploymentExpireTime = $date.AddMinutes(120)
$deploymentStartTime = new-cmschedule -start $date -Nonrecurring
$deployPurpose = 'Required'
$rerun = $true
$RerunBehavior = "AlwaysRerunProgram"
$softwareInstallation = $true
$systemRestart = $true
$useUTC = $false
$useUTCforExpireSchedule = $false
Start-CMPackageDeployment -collectionName $CollectionName -DeviceProgram -DeviceProgramName $deviceProgramName -packageName $packageName -standardprogram -schedule $deploymentStarttime -allowUsersRunIndependently $allowUsersRunIndependently -deploymentAvailableTime $deploymentAvailableTime -deploymentExpireTime $deploymentExpireTime -deployPurpose $deployPurpose -rerun $rerun -RerunBehavior $RerunBehavior -softwareInstallation $softwareInstallation -systemRestart $systemRestart -useUTC $useUTC -useUTCforExpireSchedule $useUTCforExpireSchedule
$PackageID = $(Get-CMPackage -Name $PackageName).PackageID
$deploymentStartTime = new-cmschedule -start (Get-Date).AddDays(1) -Nonrecurring
Start-CMPackageDeployment -CollectionName $CollectionName -PackageName $PackageName -standardprogram -StandardProgramName "Install" -DeployPurpose Required -DeploymentAvailableDay “2014/06/13-DeploymentAvailableTime “12:12-Schedule $deploymentStartTime -RerunBehavior RerunIfFailedPreviousAttempt -SoftwareInstallation $True -SystemRestart $False
Set-Location "c:" #change location back to c drive. Otherwise other functions break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.