Script - Add Collection to Collections - V 1.0.0.0

This is a simple script that will add a Collection to a group of other Collections based on a filter.
<#
.SYNOPSIS
Adds a Colelction to another Collection

.DESCRIPTION
The Script will add a specified Collection to either a Collection or a group of filtered Collections

.PARAMETER Filter
Filters the SCCM collections the collection is added to

.PARAMETER SiteServer
Specifyes the Site Server to connect to

.PARAMETER SiteCode
Specifies the Site Code of the SCCM enviroment

.PARAMETER LoadLocal
Tells the script to load the SCCM Module from the local computer or the server 

.EXAMPLE
Add-Collection.ps1 -CollectionToAdd "All Desktops" -Filter "Install - Available*" -LoadLocal -SiteServer "SRV-SCCM" -SiteCode "STI"
Adds the All Desktops colelction to the all collectiosn that start with Install - Avaialbe 

.NOTES
Created By: Kris Gross
Contact: Krisgross@jackofalltech.org
Twitter: @kmgamd
Script Version: 1.0.0.0

.LINK
http://www.sccmtst.com/


#>

Param(
        [Parameter(Mandatory=$true)]
        $CollectionToAdd,
        [Parameter(Mandatory=$true)]
        $Filter,
        [switch]$LoadLocal,
        [Parameter(Mandatory=$true)]
        $SiteServer,
        [Parameter(Mandatory=$true)]
        $SiteCode
    )


if ($LoadLocal -eq "$True") 
    {
        Set-Location 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\'
        Import-Module .\ConfigurationManager.psd1 -verbose:$false   
    }
    else 
    {
        Import-Module \\$SiteServer\SMS_$SiteCode\AdminConsole\bin\ConfigurationManager.psd1 -verbose:$false
    }

$site = $SiteCode + ":"
Set-Location $site


$CollectionFilter = (Get-CMDeviceCollection | Where-Object Name -Like "$Filter").name

ForEach ($Collection in ($CollectionFilter))
{
    Add-CMDeviceCollectionIncludeMembershipRule -CollectionName "$Collection" -IncludeCollectionName "$CollectionToAdd"
}

set-Location $PSScriptRoot

Comments

Popular posts from this blog

SCCM Task Sequence GUI - How to set up the TS to work with a GUI

SCCM Applications vs. SCCM Packages: Understanding the Key Differences

Faster PXE boot times in SCCM 1606 and later