Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

NEW Backup ConfigMgr Device Collections

Harshit Pandey

Well-Known Member
Messages
281
Solutions
8
Reaction score
9
Points
18
Is there a script to backup device collections and user collections in Configmgr?. I need ti because we don't have any backup software for ConfigMgr VM and I have to manually backup the collections everytime.
 
Is there a script to backup device collections and user collections in Configmgr?. I need ti because we don't have any backup software for ConfigMgr VM and I have to manually backup the collections everytime.
No but you might be able to create one with PowerShell.
But you should really backup you CM VM. If this is a lab there are LOTS of free backups SW for VMs.
 
Hello Harshit,

I think probably I have what you are looking for, I created this Script for my job.

Code:
<# ==============================================================================================
NAME: Export-SCCMSoftwareCollections.ps1
 
COMMENT: Export SCCM Windows 10 Clients Software Collections
============================================================================================== #>

# requires -version x

# change window title
$host.ui.RawUI.WindowTitle = "Export-SCCMSoftwareCollections.ps1"

## load CM CommandLets (Standard by Microsoft)
# Site configuration
$SiteCode = "001" # Site code
$ProviderMachineName = "SCCM.XXXXX.YY" # SMS Provider machine name

# Customizations
$initParams = @{}
#$initParams.Add("Verbose", $true) # Uncomment this line to enable verbose logging
#$initParams.Add("ErrorAction", "Stop") # Uncomment this line to stop the script on any errors

# Do not change anything below this line

# Import the ConfigurationManager.psd1 module
if((Get-Module ConfigurationManager) -eq $null) {
    Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" @initParams
}

# Connect to the site's drive if it is not already present
if((Get-PSDrive -Name $SiteCode -PSProvider CMSite -ErrorAction SilentlyContinue) -eq $null) {
    New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName @initParams
}

# Set the current location to be the site code.
Set-Location "$($SiteCode):\" @initParams


## Script part

$DeviceNames = (Get-CMCollectionMember -CollectionName "Windows 10 Clients").Name

foreach ($DeviceName in $DeviceNames) {

    $Applications = $Null
    $Packages = $Null

    # get Collections of device with direct rule
    $Collections = (Get-WmiObject -Namespace root/SMS/site_"$SiteCode" -Class sms_fullcollectionmembership -Filter "Name = '$DeviceName' and isDirect = '$true'")

    # get Software collections (application or package)
    $SoftwareCollections = $Collections | foreach {
        # get Name of collection
        $CollectionName = (Get-CMDeviceCollection -Id $_.CollectionID).Name
        # get deployments from collection if application=1 or package=2 / shrink to unique because some collection include multiple deployments
        Get-CMDeployment -CollectionName $CollectionName | where {$_.FeatureType -eq 1 -or $_.FeatureType -eq 2} | select ApplicationName,CollectionName,CollectionID,FeatureType
    }

    # help table to convert deployment config type
    $ApplicationDeploymentHashtable = @{1="Install";2="Uninstall"}

    # get all applications from software collections
    $Applications = $SoftwareCollections | foreach {
        if ($_.FeatureType -eq 1) {
            # set var for use in comandlet
            $CollectionID = $_.CollectionID
            $CollectionName = $_.CollectionName
            Get-CMApplication -Name $_.ApplicationName | select @{Name="Collection";Expression={$CollectionName}},@{Name="Name";Expression={$_.LocalizedDisplayName}},@{Name="Version";Expression={$_.SoftwareVersion}},Manufacturer,@{Name="CollectionID";Expression={$CollectionID}}
        }
    }

    foreach ($Application in $Applications) {
        # set var for use in comandlet
        $CollectionID = $Application.CollectionID
        $ApplicationDeployment = Get-CMApplicationDeployment -Name $Application.Name | where {$_.TargetCollectionID -eq $CollectionID}
        $Application | Add-Member -MemberType NoteProperty -Name "Action" -Value ($ApplicationDeploymentHashtable[$ApplicationDeployment.DesiredConfigType]) -Force
    }


    # get all packages from software collections
    $Packages = $SoftwareCollections | foreach {
        if ($_.FeatureType -eq 2) {
            $_ | select @{Name="Collection";Expression={$_.CollectionName}},@{Name="Name";Expression={$_.ApplicationName}},@{Name="CollectionID";Expression={$_.CollectionID}},@{Name="Action";Expression={"Package"}}
        }
    }
    
    $Software = $Applications + $Packages

    foreach ($S in $Software) { $S | Add-Member -MemberType NoteProperty -Name "Computer" -Value $DeviceName }

    $AllSoftware += $Software

}

I'm nearly sure you has to modify it, e.g. Server and Collections.

Cheers mcdy
 
Back
Top