Quantcast
Channel: PowershellTaskForce » Products
Viewing all articles
Browse latest Browse all 12

Get SCCM Collection Information from ID

$
0
0

I have been working with PowerShell and SCCM for the last 4-5 years and I have built some nice to have Functions that I often use. If you ask me :)

Now 50% of all readers will say “You don’t need to use WMI” or “You should connect in another way to WMI”.
In a new environment with SCCM 2012 and with PowerShell 3.0 or 4.0 you are probably right :)

I have been making tools and administered SCCM 2007 environments most of the time and with client computers with PowerShell 2.0. So my code will work on SCCM 2007 and SCCM 2012 environments and remote from Windows 7/8x.

This is the first one that I will publish here.

The function will show all the information from SCCM about a collection based on the Collection ID.

I wrote this one because that I some times had the Collection ID but not the name.

<#	
	.NOTES
		Created by:   	Fredrik Wall
		Blog: 	Poweradmin.se/PowershellTaskForce.com

	.SYNOPSIS
		Get Collection Information from Collection ID
	
	.DESCRIPTION
		A detailed description of the Get-SCCMCollectionInfoFromID function.
	
	.EXAMPLE
				Get-SMSCollectionInfoFromID
	.EXAMPLE
				(Get-SCCMCollectionInfoFromID).Name
	.EXAMPLE
				Get-SMSCollectionInfoFromID | gm
#>
function Get-SCCMCollectionInfoFromID
{
	[CmdletBinding()]
	param (
		[Parameter(Mandatory = $True)]
		$SiteServer,
		[Parameter(Mandatory = $True)]
		$SiteCode,
		[Parameter(Mandatory = $True)]
		$CollectionID
	)
	
	$Collection = Get-WmiObject -Namespace "root\SMS\Site_$SiteCode" -Query "select * from SMS_Collection Where SMS_Collection.CollectionID='$CollectionID'" -computername $SiteServer
	$Collection
}

(Get-SCCMCollectionInfoFromID -SiteServer LabSCCMSrv01 -SiteCode MYS -CollectionID MYS00125).Name

Fredrik W Test Collection

Or if you write

Get-SCCMCollectionInfoFromID -SiteServer LabSCCMSrv01 -SiteCode MYS -CollectionID MYS00125

You will get all of the information from this collection.

I only use this one when I know that I have the right ID so I don’t have error handling in it for that reason.


Viewing all articles
Browse latest Browse all 12

Trending Articles