In System Center Configuration Manager 2012 R2 it is not possible to export update groups and even if it is not an everyday task in some circumstance this can be useful… In my case I had to copy all my production updates groups to our acceptance environnement and doing this by hand was not an option at all so I wrote this little Cmdlet :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1") $SiteCode = Get-PSDrive -PSProvider CMSITE CD "$($SiteCode):\" Function Export-CMSoftwareUpdateGroups { param( [string]$SoftwareUpdateGroupName = "*", [string]$Output = "$env:windir\temp\UpdatesExport.xml" ) process { $SoftwareUpdateGroups = @(Get-CMSoftwareUpdateGroup -Name $SoftwareUpdateGroupName) [System.Xml.XmlDocument]$XmlDocument = New-Object System.Xml.XmlDocument [System.Xml.XmlNode]$Root = $XmlDocument.CreateElement("SoftwareUpdateGroups") $XmlDocument.AppendChild($Root) $SoftwareUpdates = @() foreach($SoftwareUpdateGroup in $SoftwareUpdateGroups) { [System.Xml.XmlNode]$SoftwareUpdateGroupNode = $XmlDocument.CreateElement("SoftwareUpdateGroup") $Root.AppendChild($SoftwareUpdateGroupNode) [System.Xml.XmlNode]$SoftwareUpdateGroupNameNode = $XmlDocument.CreateElement("SoftwareUpdateGroupName") $SoftwareUpdateGroupNameNode.InnerText = $($SoftwareUpdateGroup.LocalizedDisplayName) $SoftwareUpdateGroupNode.AppendChild($SoftwareUpdateGroupNameNode) [System.Xml.XmlNode]$SoftwareUpdateGroupIDsNode = $XmlDocument.CreateElement("SoftwareUpdateGroupIDs") $SoftwareUpdateGroupNode.AppendChild($SoftwareUpdateGroupIDsNode) [string[]]$SoftwareUpdates = @() foreach($Update in $SoftwareUpdateGroup.Updates) { $SoftwareUpdateName = $(Get-CMSoftwareUpdate -id $Update).LocalizedDisplayName [System.Xml.XmlNode]$SoftwareUpdateGroupIDNode = $XmlDocument.CreateElement("SoftwareUpdateGroupID") $SoftwareUpdateGroupIDNode.InnerText = $SoftwareUpdateName $SoftwareUpdateGroupIDsNode.AppendChild($SoftwareUpdateGroupIDNode) $SoftwareUpdates += $SoftwareUpdateName } $SoftwareUpdates += [pscustomobject]@{ LocalizedDisplayName = $($SoftwareUpdateGroup.LocalizedDisplayName) Updates = $SoftwareUpdates } } $XmlDocument.Save($Output) return $SoftwareUpdates } } $ExportedUpdateGroups = Export-CMSoftwareUpdateGroups -SoftwareUpdateGroupName "ADR - *" -Output "c:\temp\UpdatesExport.xml" |
The next post will be about importing the data in another Configuration Manager environnement !
Hi Phil,
When I run the script, I get a blank XML file that only has in it. Please help
Cheers
Nick
Hi Nick,
May I see the syntax you used to run the cmdled ? I’ve just tried to run it to spot any problem and it ran fine…
Kr,
PHiL