PoshCode Archive  Artifact [bca1f90502]

Artifact bca1f9050269436248164c1ae615e1ab69e66c8d2b95b2e0116ecbbb9341bbdc:

  • File Create-SCCMCollection.ps1 — part of check-in [37800c74d1] at 2018-06-10 13:07:34 on branch trunk — This script will create a new System Center Configuration Manager (SCCM) 2007 Collection. (user: Andy S size: 1254)

# encoding: ascii
# api: powershell
# title: Create-SCCMCollection
# description: This script will create a new System Center Configuration Manager (SCCM) 2007 Collection.
# version: 0.1
# type: function
# author: Andy S
# license: CC0
# function: Create-SCCMCollection
# x-poshcode-id: 2229
# x-archived: 2016-06-05T08:39:32
# x-published: 2011-09-12T07:52:00
#
# Usage:
# Create-SCCMCollection -Server localhost -Name NewCollection -Site Site1 -ParentCollectionID COLLROOT
#
function Create-SCCMCollection
{
param($Server = $Env:ComputerName, $Name, $Site, $ParentCollectionID = "COLLROOT")

$ColClass = [WMIClass]"\\$Server\Root\SMS\Site_$($Site):SMS_Collection"
$Col = $ColClass.PSBase.CreateInstance()
$Col.Name = $Name
$Col.OwnedByThisSite = $True
$Col.Comment = "Collection $Name"
$Col.psbase
$Col.psbase.Put()

$NewCollectionID = (Get-WmiObject -computerName $Server -namespace Root\SMS\Site_$Site -class SMS_Collection | where {$_.Name -eq $Name}).CollectionID
				
$RelClass = [WMIClass]"\\$Server\Root\SMS\Site_$($Site):SMS_CollectToSubCollect"
$Rel = $RelClass.PSBase.CreateInstance()
$Rel.ParentCollectionID = $ParentCollectionID
$Rel.SubCollectionID = $NewCollectionID
$Rel.psbase
$Rel.psbase.Put()

}