WordPress.com



#################################################

## Created By: Luke Salter ##

## Created On: 07/05/2014 ##

## Modified On: 15/05/2014 ##

## SCCM Collection&Deployment - CSV Input ##

#################################################

## Load Configuration Manager Module and Switch to EH Site Server

CD "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin"

import-module .\ConfigurationManager.psd1

CD EH1:

function createcollection {

## Creates Collection based on the Name read in the CSV File

New-CMDeviceCollection -name $CollectionName -LimitingCollectionName "All Systems"

## Creates a Query based rule for the Collection just created. Query looks at AD for name read in the CSV File

Add-CMDeviceCollectionQueryMembershipRule -RuleName $CollectionName -Collectionname $CollectionName -QueryExpression "select * from SMS_R_System where SMS_R_System.SystemGroupName = 'EH\\SCCM2012_DL_$CollectionName'"

## Connects to the site WMI namespace and reads the CollectionID for the collection created.

$collection = gwmi -Namespace root\sms\site_EH1 -Class SMS_Collection | where {$_.Name -eq "$collectionName"}

$collID = $collection.CollectionID

## Creates Variables for moving the collection

[Array]$DeviceCollectionID = $collid

$TargetFolderID = 16777228 ## Target Folder = Applications

$CurrentFolderID = 0 ## Current Directory = Root

$ObjectTypeID = 5000 ## Object Type = Computer (5001 for User)

## Moves the collection

Invoke-WmiMethod -Namespace "Root\SMS\Site_EH1" -Class SMS_objectContainerItem -Name MoveMembers -ArgumentList $CurrentFolderID,$DeviceCollectionID,$ObjectTypeID,$TargetFolderID

$Collectionname | Out-File C:\Temp\Powershell\'Collection Creation'\CreatedDeviceCollections.txt -append

$DeviceCollectionID | Out-File C:\Temp\Powershell\'Collection Creation'\CreatedDeviceCollections.txt -append

}

function CreateDeployment {

## Distribute Content

Start-CMContentDistribution -PackageName $AppName -DistributionPointGroupName "All Distribution Points"

## Create Package Deployment

Start-CMPackageDeployment -PackageName $AppName -StandardProgramName $InstType -CollectionName $CollectionName -Comment "Created Automatically" -DeployPurpose Required -ScheduleEvent AsSoonAsPossible -FastNetworkOption DownloadContentFromDistributionPointAndRunLocally -SlowNetworkOption DownloadContentFromDistributionPointAndLocally

}

## Read Applications CSV File

import-csv 'C:\Temp\Powershell\Collection Creation\Applications.csv' | foreach {

## Create Install Variable

$InstType = '_Install'

## Collection Name Variable for each row in the CSV File

$AppName=$_.APP

$CollectionName=$AppName+$InstType

## Check Existing Collection

IF(!(Get-WmiObject -Namespace "root\SMS\Site_EH1" -Query "Select * from SMS_Collection where name = '$CollectionName'" | Select-Object Name))

{createcollection

CreateDeployment}

ELSE

{$Collectionname | Out-File C:\Temp\Powershell\'Collection Creation'\ExistingDeviceCollections.txt -append}

}

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download