The Challenge
Configuration Manager (CM) provides a robust infrastructure for managing devices in large organizations. A critical component of this is the ‘maintenance window‘ which ensures that deployments occur during designated times, minimizing disruptions. But how do you obtain a comprehensive view of these windows across multiple device collections?
The Problem
For administrators managing an extensive environment, navigating through the CM console to fetch details about maintenance windows can be tedious. Manual approaches are time-consuming, error-prone, and not scalable. Moreover, crafting extensive SQL queries might not be feasible for everyone.
The Solution
Enter our streamlined script tailored for this specific challenge. Here’s a snapshot of its functionality:
- Initialization: It kicks off by importing the necessary Configuration Manager module and setting the required site location.
- Targeted Query: The script then dives deep, querying all device collections inside a designated Software Updates folder.
- Fetching Details: For each identified collection, it meticulously fetches the associated maintenance window details.
- User-Friendly Presentation: The data, once collated, is presented in a structured grid view, making it easy for users to interpret and make decisions.
This script is not just about simplifying a process; it’s about empowering CM administrators to have the right data at their fingertips. Whether it’s for compliance checks, deployment planning, or auditing, this tool is designed to be both efficient and adaptable.
A word of caution: As with any script that interacts with your environment, always test in a sandbox or development setup first. This ensures safety and maintains the integrity of your production systems.
The Script
#Import Configuration Manager Module
Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
$SiteCode = Get-PSDrive -PSProvider CMSITE
Set-Location "$($SiteCode.Name):\"
$SWUpdatesFolderID = 16777224 #Software Updates Device Collection Folder. Use the Get-CMFolder cmdlet to identify the ContainerNodeID
$SiteCode = $SiteCode.Name
$MaintenanceWindows = @()
#Query All Collections from Software Updates Folder
$CollectionsInSpecficFolder = Get-CimInstance -Namespace "ROOT\SMS\Site_$SiteCode" `
-Query "select * from SMS_Collection where CollectionID is in(select InstanceKey from SMS_ObjectContainerItem where ObjectType='5000' and ContainerNodeID='$SWUpdatesFolderID') and CollectionType='2'"
Write-Output -InputObject "Device Collections in $SWUpdatesFolderID folder: $($CollectionsInSpecficFolder.Count)"
foreach($Collection in $CollectionsInSpecficFolder){
Write-Output -InputObject "Quering $($Collection.Name) Device Collection"
#Using ConfigMgr PowerShell module Get-CMMaintenanceWindow cmdlet
$MWQuery = Get-CMMaintenanceWindow -CollectionId $Collection.CollectionID
$Props = {
[Ordered]@{
Collection = $Collection.Name
CollectionID = $Collection.CollectionID
MWName = $MWQuery.Name
IsEnabled = $MWQuery.IsEnabled
Duration = $MWQuery.Duration
Description = $MWQuery.Description
ServiceWindowType = switch($MWQuery.ServiceWindowType){1{'All Deployments'}4{'Software Updates'}5{'Task Sequences'}}
StartTime = $MWQuery.StartTime
}
}
$MaintenanceWindows += New-Object PSObject -Property (&$Props)
}
$MaintenanceWindows | Out-GridView -Title "Maintenance Windows in $SWUpdatesFolderID folder: $(Get-Date)"