TechEd Australia 2013 – PowerShell for ConfigMgr 2012 SP1 – Demo 4

 Demo 4: Packages

Automatically create Package from source directory, create Deployment Type, create Collection and Deployment

$ErrorActionPreference = “Stop”
Set-Location C:
$NewPackageLocation = “\TECHED13NewPackages*”
$CorpSourcelocation = “\TECHED13Source$Packages”
$NewPackageLocation = Get-Item $NewPackageLocation
Copy-Item $NewPackageLocation -Destination $CorpSourcelocation -Recurse
Remove-Item $NewPackageLocation -Recurse
$PackageSourcePath = $CorpSourcelocation + ” + $NewPackageLocation.Name
$SplitValues = $NewPackageLocation.Name.Split(“-“)
$PackageManufacturer = $SplitValues[0]
$PackageName = $SplitValues[1]
$PackageVersion = $SplitValues[2]
$PackageLanguage = $SplitValues[3]
Import-Module ‘C:Program Files (x86)Microsoft Configuration ManagerAdminConsolebinConfigurationManager.psd1’
Set-Location PRI:
New-CMPackage -Path $PackageSourcePath -Name $PackageName -Manufacturer $PackageManufacturer -Version $PackageVersion -Language $PackageLanguage -Description “Created Using PowerShell”
New-CMProgram -PackageName $PackageName -StandardProgramName “Setup $PackageName” -CommandLine “msiexec /i setup.msi /q”
Start-CMContentDistribution -PackageName $PackageName -DistributionPointGroupName “All DPs”
New-CMDeviceCollection -Name “Install –  $PackageManufacturer$PackageName$PackageLanguage$PackageVersion” -LimitingCollectionName “All Systems”
Start-CMPackageDeployment -PackageName $PackageName -StandardProgramName “Setup $PackageName” -CollectionName “Install –  $PackageManufacturer$PackageName$PackageLanguage$PackageVersion” -DeployPurpose Available