It’s been awhile and I’ve been having way to much fun with ConfigMgr 2012. I’ve been working for the last year on large deployment and would like to share some of the items that have made my day just a bit easier.
This article assumes you are all familiar with the PowerShell cmdLets introduced in SP1 and forward. If not go here and welcome to the fun.
My current environment we have a lot of collections based upon dynamic AD group memberships. I do not have control of when devices are add, moved or deleted from AD. Some of these collections have very tight Maintenance Windows (MW) applied. To complicate matters worse we also have very strict patching deadlines for compliance that follow a schedule. After discovering that some of my devices were added to a collection due to an updated AD Group membership that had MW applied post compliance reporting day. Needless to say they were not compliant.
I live for scripting especially if ConfigMgr is involved. I also enjoy PowerShell and Console Extensions. What an opportunity.
Disclaimer – there are always more than one way to get information. This is my method.
A MW can be viewed in the Console in the individual collection properties.
Well that sucks for me as I have many Collections and some with MW windows. I would much prefer to click on a device in the Console and say “show me your MW windows”. So now goal has been defined. Let’s jump into GUID hell
Yup – it’s good.
I created a new .xml for my right click console action:
<ActionDescription Class="Group" DisplayName="Show Me My Maintenance Windows" MnemonicDisplayName="Show Me My Maintenance Windows" Description="Show Me My Maintenance Windows"><ShowOn><string>DefaultHomeTab</string><string>ContextMenu</string> </ShowOn><ActionGroups> <ActionDescription Class="Executable" DisplayName="Show Me My Maintenance Windows" MnemonicDisplayName="Show Me My Maintenance Windows" Description = "Show Me My Maintenance Windows" RibbonDisplayType="TextAndSmallImage"><ShowOn><string>ContextMenu</string><string>DefaultHomeTab</string></ShowOn><Executable><FilePath>showmw.bat</FilePath><Parameters>"##SUB:Name##"</Parameters></Executable></ActionDescription></ActionGroups></ActionDescription>
I use a batch file so I can make quick changes to avoid closing the console and refreshing the right click xml.
And yup – this one does have a MW.
The Powershell script.
You can modify the script to remove the NetBIOS_name0 clause to find all devices if desired. This is just the start framework and the possibilities are endless to instant information with PowerShell and ConfigMgr.
Until next time.
Can you extend the script to convert the NextServiceWindow time which is in UTC to client local time?
When I run this script I get this error:
Exception calling "Fill" with "1" argument(s): "Invalid object name 'dbo.SCCM_GetNextServiceWindow'."
At C:\Users\username\Desktop\New Text Document.ps1:63 char:5
+ $DataAdapter.fill($DataSet) |out-null
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : SqlException
Great article, thanks for sharing.
Yes, this comes very handy especially when we have too many clients in different locations. Client local time will be very helpful.
You should be able to resolve the issue by replacing the lines between 064 to 068 with
$DataTable = new-object system.data.datatable
$DataTable = $DataSet.Tables
$ServiceWindows = @($DataTable)
Hope this helps!!
Actually it's because you probably don't have the SCCM_GetNextServiceWindow function. You'd have to run this in SQL to create it first.
You can find the t-sql here: