Jump to content


Recommended Posts

Hello All,

 

I have a Powershell script that I use to create multiple Software Update Deployments and it works perfectly (well almost). The last piece I'm missing is automating the deadline date. Currently I just have it getting the current date and adding 5 days. I then go into each deployments properties and change the date/time to the desired info.

 

I've been trying to work out automating this a little bit by adding a variable for a static date/time. I can then change this date (time will always be the same) to the desired info at script run. Below is what I've come up with so far. The -EnforcementDeadlineDay piece works on it own, in that it outputs the correct date with an incremented time. However once I put it in the full script i get the below errors.

 

Any help is much appreciated.

 

Cheers,

Mike

 

Script:

# Monthly Deployment Date
#$DeploymentDate = Get-Date -Format "yyyy-MM"
$DeploymentDate = (Get-Date).AddDays(-30).ToString("yyyy-MM")
$DeadlineDate = Get-Date -Month 08 -Day 07 -Year 2016 -Hour 17 -Minute 0 -Second 0

# Software Update Groups
$SUPGroupName1 = "EN5 - EDC - Year 2013- ($DeploymentDate) Reference 1"
$SUPGroupName2 = "EN5 - EDC - Year 2013+ ($DeploymentDate) Reference 2"

#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
Set-location $SiteCode":"

# Create Standard Deployments (Group 1)
$DeploymentName = "EN5 - PM Dev ($DeploymentDate) Reboot Deployment # 1"
$DeploymentCount = 6
$Count = 0
1..$DeploymentCount | ForEach-Object {
    $Count++
    Write-Progress -Activity "Creating Deployment Group 1" -Id 1 -Status "Running $($Count) / $($DeploymentCount)" -PercentComplete (($Count / $DeploymentCount) * 100)
    Start-CMSoftwareUpdateDeployment -SoftwareUpdateGroupName "$SUPGroupName1" -CollectionName "EN5 - PM - Deployment $Count (Lab)" -DeploymentName "$DeploymentName-$Count" -DeploymentType Required -VerbosityLevel AllMessages -TimeBasedOn LocalTime -DeploymentAvailableDay (Get-Date) -EnforcementDeadlineDay $DeadlineDate.ToLongDateString()$DeadlineDate.Addhours($Count).ToLongTimeString() -UserNotification HideAll -SoftwareInstallation $True -AllowRestart $True -RestartServer $False -RestartWorkstation $False -ProtectedType RemoteDistributionPoint -UnprotectedType UnprotectedDistributionPoint -GenerateSuccessAlert $False -DisableOperationsManagerAlert $False -GenerateOperationsManagerAlert $False -PersistOnWriteFilterDevice $False -UseBranchCache $False
}
Write-Progress -Activity "Creating Deployment Group 1" -Id 1 -Completed

Errors:

Start-CMSoftwareUpdateDeployment : A positional parameter cannot be found that accepts argument '6:00:00 PM'.
At E:\scripts\EN5 - CreateDeployments - LAB.ps1:24 char:5
+     Start-CMSoftwareUpdateDeployment -SoftwareUpdateGroupName "$SUPGroupName1" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: ( [Start-CMSoftwareUpdateDeployment], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ConfigurationManagement.Cmdlets.Sum.Commands.StartSoftwareUpdateDeploymentCommand
 
Start-CMSoftwareUpdateDeployment : A positional parameter cannot be found that accepts argument '7:00:00 PM'.
At E:\scripts\EN5 - CreateDeployments - LAB.ps1:24 char:5
+     Start-CMSoftwareUpdateDeployment -SoftwareUpdateGroupName "$SUPGroupName1" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: ( [Start-CMSoftwareUpdateDeployment], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ConfigurationManagement.Cmdlets.Sum.Commands.StartSoftwareUpdateDeploymentCommand
 
Start-CMSoftwareUpdateDeployment : A positional parameter cannot be found that accepts argument '8:00:00 PM'.
At E:\scripts\EN5 - CreateDeployments - LAB.ps1:24 char:5
+     Start-CMSoftwareUpdateDeployment -SoftwareUpdateGroupName "$SUPGroupName1" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: ( [Start-CMSoftwareUpdateDeployment], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ConfigurationManagement.Cmdlets.Sum.Commands.StartSoftwareUpdateDeploymentCommand
 
Start-CMSoftwareUpdateDeployment : A positional parameter cannot be found that accepts argument '9:00:00 PM'.
At E:\scripts\EN5 - CreateDeployments - LAB.ps1:24 char:5
+     Start-CMSoftwareUpdateDeployment -SoftwareUpdateGroupName "$SUPGroupName1" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: ( [Start-CMSoftwareUpdateDeployment], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ConfigurationManagement.Cmdlets.Sum.Commands.StartSoftwareUpdateDeploymentCommand
 
Start-CMSoftwareUpdateDeployment : A positional parameter cannot be found that accepts argument '10:00:00 PM'.
At E:\scripts\EN5 - CreateDeployments - LAB.ps1:24 char:5
+     Start-CMSoftwareUpdateDeployment -SoftwareUpdateGroupName "$SUPGroupName1" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: ( [Start-CMSoftwareUpdateDeployment], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ConfigurationManagement.Cmdlets.Sum.Commands.StartSoftwareUpdateDeploymentCommand
 
Start-CMSoftwareUpdateDeployment : A positional parameter cannot be found that accepts argument '11:00:00 PM'.
At E:\scripts\EN5 - CreateDeployments - LAB.ps1:24 char:5
+     Start-CMSoftwareUpdateDeployment -SoftwareUpdateGroupName "$SUPGroupName1" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: ( [Start-CMSoftwareUpdateDeployment], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ConfigurationManagement.Cmdlets.Sum.Commands.StartSoftwareUpdateDeploymentCommand

Share this post


Link to post
Share on other sites

Figured it out. I didn't realize there were two params for deadline enforcement.

 

-EnforcementDeadline

-EnforcementDeadlineDay

 

Clearly the latter (which I was using) only supports the date (day).

 

I switched to the first one and I am getting the correct times now but the date is being increased by 7 days from the current day for some reason. (ex. today is 8/4, despite my script saying the deadline date should be 8/7 it makes it 8/11)

 

Anyway, thanks for looking. Maybe this will help someone else.

 

EDIT: Here is what I ended up with. Sets the correct date and time

# Set Deadline Date and Time
$DeadlineDay = Get-Date -Month 08 -Day 08 -Year 2016
$DeadlineTime = Get-Date -Hour 16 -Minute 0 -Second 0


-EnforcementDeadlineDay $DeadlineDay -EnforcementDeadline $DeadlineTime.AddHours($Count)

Cheers,

Mike

Share this post


Link to post
Share on other sites

Nice script! I did find this very helpful :)

I was able to determine (8 years later) that the initial error was that you were passing 2 dates at the same time to the one command.

-EnforcementDeadlineDay $DeadlineDate.addhours($Count) is all you needed in order to up the deadline time, instead of:

-EnforcementDeadlineDay $DeadlineDate.ToLongDateString()$DeadlineDate.Addhours($Count).ToLongTimeString()

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.