# 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: 850
# x-archived: 2016-06-03T06:44:33
# x-published: 2009-02-04T13:44: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()
}