Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NathanTheGr8/8553778003cf969da6adebe4f487c5b0 to your computer and use it in GitHub Desktop.
Save NathanTheGr8/8553778003cf969da6adebe4f487c5b0 to your computer and use it in GitHub Desktop.
function Schedule-SCCMPackageDeployment
{
<#
.SYNOPSIS
.DESCRIPTION
requires \\spivsccm01\packages mounted as p Drive
.PARAMETER App
.EXAMPLE 1
.Links
#>
[CmdletBinding(ConfirmImpact = 'None')]
param
(
[string]
$PackageName,
[Parameter(Mandatory = $true,
HelpMessage = 'List of Computers')]
[string[]]
$Computers
#[string]$time
)
$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