PoSh on SCCM2012 SP1


Today we perform some basic actions on sccm2012 SP1 using powershell.

Step 1 :

On server 2008 R2 make sure to have PoSh 3.0 installed.


First choice : connect using console.

Or do it manually ( use X86 powershell prompt )

Import-module <Config Mgr installation>\Adminconsole\bin\ConfigurationManager.psd1

Also verify that the process execution policy is set to RemoteSigned if you run scripts directly from the config manager powershell prompt.

You can see that you have an additional drive available by using the get-psdrive cmd.Change the location of the prompt like this : cd <SiteName>:

You can use this script in order to create a collection based on the active directory sites. Each site has a query in order to add all the resources that have that specific AD site as property.

Enjoy …

# requires posh 3.0 and CM psd

# create CM collections based on resource AD site

function FcreateCMCollection ($ADSiteName)


# Modify the variable for the correct limiting collection

$LimitingCollection = “COL_Workstations”

new-cmdevicecollection -Name “COL_WKS_$ADSiteName” -LimitingCollectionName $LimitingCollection

$queryRule =”select

SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.ADSiteName ='”+ $adsitename +”‘”

add-cmdevicecollectionquerymembershiprule -Collectionname “COL_WKS_$ADSiteName” -RuleName “Q_$ADSIteName” -Queryexpression $Queryrule


Function FDUmpADSItesCsv


# Dump all the ad sites in a csv document

import-module activedirectory

$forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()

$adSites = $forest.Sites

$adSites | select name | Export-Csv c:\Temp\globalsites.csv -NoTypeInformation


import-module “D:\program files\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1”

$adsites = import-csv c:\Temp\globalsites.csv

Foreach ($site in $adsites )


$site = $Site.name




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s