PoshCode Archive  Artifact [16ab34a275]

Artifact 16ab34a275359a2c58f09659a3842e2fc847c9b6a5de1f1096dac91d6544819b:

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

# 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()

}