Search code examples
powershellsccm

SCCM - Change existing deployment deadlines with PowerShell


We use SCCM 2016 to install Microsoft updates and have multiple deployments with deadlines of past dates. I'd like to be able to push those deadlines to a future date using a script, as manually changing per deployment with the GUI is time consuming.

enter image description here

This command shows me the deployments of interest:

Get-CMDeployment | Select-Object -Property * | Where-Object {`
$_.SoftwareName -like '*SecurityUpdates*' -and $_.CollectionName -like '*Servers*'
}

My research shows I should use Set-CMSoftwareUpdateDeployment to modify the deadline of existing deployments. However this is where I'm stuck. According to the following thread, the parameters I should use to define a new deadline are DeploymentExpireDay and DeploymentExpireTime, as well as make sure the deployment is set to required: https://social.technet.microsoft.com/Forums/ie/en-US/11f977f4-09d1-4127-b8ce-7cdb19c88d1b/update-deployment-installation-deadlines-via-powershell?forum=configmanagersecurity

Unsure how to construct a working command, I consulted the cmdlet's MS documentation: https://learn.microsoft.com/en-us/powershell/module/configurationmanager/set-cmsoftwareupdatedeployment?view=sccm-ps

Looking at the doco, DeploymentExpireDay and DeploymentExpireTime aren't listed in the parameters list. Only DeploymentExpireDateTime is in the list. However, to add to the confusion, those two parameters are included in the examples whereas DeploymentExpireDateTime is not.

I connect to SCCM like this:

#Load Configuration Manager PowerShell Module
Import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1')

#Get SiteCode and set Powershell Drive
$SiteCode = (Get-PSDrive -PSProvider CMSITE).Name
Push-Location "$($SiteCode):\"    

I tried this:

$DeadlineDay = Get-Date -Month 11 -Day 08 -Year 2018
$DeadlineTime = Get-Date -Hour 16 -Minute 0 -Second 0

Set-CMSoftwareUpdateDeployment `
-DeploymentName "Deployment Name" `
-DeploymentType Required `
-DeploymentExpireDay $DeadlineDay `
-DeploymentExpireTime $DeadlineTime

But I get this:

Set-CMSoftwareUpdateDeployment : A parameter cannot be found that matches parameter name 'DeploymentExpireDay'.
At line:1 char:104
+ ... ment Name" -DeploymentType Required -DeploymentExpireDay $Deadli ...
+                                              ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-CMSoftwareUpdateDeployment], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ConfigurationManagement.Cmdlets.Deployments.Commands.SetSoftwareUpdateDeploymentCommand

So I tried this:

$date = (Get-Date).AddDays(20)
Set-CMSoftwareUpdateDeployment `
-DeploymentName "Deployment Name" `
-DeploymentType Required `
-DeploymentExpireDateTime $date

But I get this:

cmdlet Set-CMSoftwareUpdateDeployment at command pipeline position 1
Supply values for the following parameters:
InputObject: 
PS SCM:\>

Can anyone direct me as to what I'm doing wrong? Thanks in advance!


Solution

  • You probably need more information than just the DeploymentName to make this recognizable. Try Specifying The parameter -SoftwareUpdateGroupName as well was as -DeploymentName so

    $date = (Get-Date).AddDays(20)
    Set-CMSoftwareUpdateDeployment `
    -DeploymentName "Deployment Name" `
    -SoftwareUpdateGroupName "Software Update Group Name" `
    -DeploymentType Required `
    -DeploymentExpireDateTime $date
    

    If you don't know the software update group name I would go a totally different route.

    First get the deployments with

    Get-CMSoftwareUpdateDeployment 
    

    I think in your case you will just want all of them anyway but if not you probably have to filter with "where" because the -Name parameter seems to be broken.

    Then use the objects you get as InputObject for Set-CMSoftwareUpdateDeployment ingoring the name and modifying the time:

    Get-CMSoftwareUpdateDeployment | where {$_.AssignmentName -eq "Deployment Name"}
    | Set-CMSoftwareUpdateDeployment -DeploymentExpireDateTime (Get-Date).AddDays(20)