Delete old SCCM Deployments

This PowerShell script deletes old SCCM Deployments.The script will prompt the user to enter the desired date and the script will list all deployment older than the specified date.The user will be prompt before each deployment deletion before going to the next one.The script supp

 
 
 
 
 
5 Star
(2)
1,515 times
Add to favorites
System Center
6/6/2018
E-mail Twitter del.icio.us Digg Facebook
  • Date in error
    3 Posts | Last post October 24, 2019
    • Apparently there are several date format in the database!!!
      
      Get-CMDeployment | Where-Object {$_.CreationTime -le '09012019'}
      
      ------------------------------------------------------------------------------------------
      SmsProviderObjectPath : SMS_DeploymentSummary.DeploymentID="UCP2005F"
      ApplicationName       : ISS - Desktop - Fireamp - CHANGE RESTART OPTIONS!!!!! (ISS - Desktop - FireAmp)
      AssignmentID          : 0
      CI_ID                 : 
      CollectionID          : UCP0019A
      CollectionName        : ISS - Desktop - Lab Test Computers
      CollectionType        : 2
      CreationTime          : 
      DeploymentID          : UCP2005F
      DeploymentIntent      : 1
      DeploymentTime        : 1/18/2018 10:08:00 AM
      DesiredConfigType     : 1
      EnforcementDeadline   : 
      FeatureType           : 2
      ModelName             : 
      ModificationTime      : 1/18/2018 6:08:02 PM
      NumberErrors          : 33
      NumberInProgress      : 5
      NumberOther           : 0
      NumberSuccess         : 12
      NumberTargeted        : 50
      NumberUnknown         : 0
      ObjectTypeID          : 201
      PackageID             : UCP000AE
      PolicyModelID         : 0
      ProgramName           : ISS - Desktop - FireAmp
      RequireApproval       : 
      SecuredObjectId       : UCP2005F
      SoftwareName          : ISS - Desktop - Fireamp - CHANGE RESTART OPTIONS!!!!! (ISS - Desktop - FireAmp)
      SummarizationTime     : 10/18/2019 12:02:46 PM
      SummaryType           : 2
      
      ------------------------------------------------------------------------------------------
      
      Thanks,
      Dom
    • -----------------------------------------------------------------------------------------
      or in error like:
      ---------------------------------------------------------------------
      "Could not compare "10/23/2019 04:10:26" to "09012019". Error: "Cannot convert value "09012019" to type "System.DateTime". Error: "String was not recognized as a valid 
      DateTime.""
      At line:1 char:34
      + Get-CMDeployment | Where-Object {$_.CreationTime -le '09012019'}
      +                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
          + FullyQualifiedErrorId : ComparisonFailure"
      -------------------------------------------------------------------------------------------
      
      Thanks,
      Dom
    • I think I find out the error the date should have a specific format
      Get-CMDeployment | Where-Object {$_.CreationTime -le '09/01/2019 00:00:00'}
      works...
      
      next step :)
      Thanks,
      Dom