In time I will update this post with a breakdown of how it works but I am posting it in full now to support my blog post on Planning the bulk import of applications into SCCM 2012 R2
It is heavily influenced by the following three articles:
- http://www.david-obrien.net/2013/07/create-new-configmgr-applications-from-script-with-powershell/
- http://www.dexterposh.com/2014/04/powershell-sccm-2012-r2-create-folders.html
- http://www.dexterposh.com/2014/03/powershell-sccm-2012-r2-create.html
This script is not intended for production use but everything works as intended.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# Description: POC batch import applications into SCCM based upon an XML description # Created: 7/10/2015 # Author: Mark Allen # Usage: .\New-Applications.ps1 -SiteCode PR1 -Path \\%PathToXMLFile% # References: # http://www.david-obrien.net/2013/07/create-new-configmgr-applications-from-script-with-powershell/ # http://www.dexterposh.com/2014/04/powershell-sccm-2012-r2-create-folders.html # http://www.dexterposh.com/2014/03/powershell-sccm-2012-r2-create.html [CmdletBinding( SupportsShouldProcess = $False, ConfirmImpact = "None", DefaultParameterSetName = "" ) ] param( [string]$SiteCode, [ValidateScript({Test-Path $(Split-Path $_) -PathType 'Container'})] [string]$Path ) $WhatIfPreference = $true $DistributionPointGroupName = 'MY DPG' $CollectionName = 'All Users' $DeployAction = 'Install' $DeployPurpose = 'Available' [xml]$Applications = Get-Content $Path Import-Module ($env:SMS_ADMIN_UI_PATH.Substring(0,$env:SMS_ADMIN_UI_PATH.Length – 5) + '\ConfigurationManager.psd1') | Out-Null #CM12 cmdlets need to be run from the CM12 drive Set-Location "$($SiteCode):" | Out-Null if (-not (Get-PSDrive -Name $SiteCode)) { Write-Error "There was a problem loading the Configuration Manager powershell module and accessing the site's PSDrive." exit 1 } foreach ($App in $Applications.Applications.Application) { "Adding App $($App.Name)" if ($App.AutoInstall) { $NewApp = New-CMApplication -Name "$($App.Name)" -Description "$($App.Description)" -Publisher "$($App.Manufacturer)" -SoftwareVersion "$($App.SoftwareVersion)" -AutoInstall $true } else { $NewApp = New-CMApplication -Name "$($App.Name)" -Description "$($App.Description)" -Publisher "$($App.Manufacturer)" -SoftwareVersion "$($App.SoftwareVersion)" } switch -regex ($($App.Manufacturer).Substring(0,1).ToUpper()) { "[A-F]" {$AppDIr = "A-F"} "[G-L]" {$AppDIr = "G-L"} "[M-R]" {$AppDIr = "M-R"} "[S-Z]" {$AppDIr = "S-Z"} default {$AppDIr = NULL} } if ($AppDIr) { " - Moving the Application to the $AppDIr folder" Move-CMObject -FolderPath .\Application\$AppDIr -InputObject $(Get-CMApplication -Name $App.Name) } foreach ($DeploymentType in $App.DeploymentTypes) { if ($DeploymentType.DeploymentType.MsiInstaller) { " - Adding DT for MSI Installer" " - - File: $($DeploymentType.DeploymentType.InstallationFileLocation)" Add-CMDeploymentType -ApplicationName "$($NewApp.LocalizedDisplayName)" -InstallationFileLocation "$($DeploymentType.DeploymentType.InstallationFileLocation)" -InstallationProgram "$($DeploymentType.DeploymentType.InstallationProgram)" -MsiInstaller -AutoIdentifyFromInstallationFile -ForceForUnknownPublisher $true } if ($DeploymentType.DeploymentType.ScriptInstaller) { " - Adding DT for Script Installer" " - - DT Name: $($DeploymentType.DeploymentType.DeploymentTypeName)" [string]$ContentLocation = ($DeploymentType.DeploymentType.ContentLocation) $ContentLocation = $ContentLocation.Trim() Add-CMDeploymentType -ApplicationName "$($NewApp.LocalizedDisplayName)" -ScriptInstaller -DeploymentTypeName "$($DeploymentType.DeploymentType.DeploymentTypeName)" -InstallationProgram "$($DeploymentType.DeploymentType.InstallationProgram)" -InstallationBehaviorType "$($DeploymentType.DeploymentType.InstallationBehaviorType)" -LogonRequirementType "$($DeploymentType.DeploymentType.LogonRequirementType)" -ContentLocation "$($ContentLocation)" -ManualSpecifyDeploymentType -DetectDeploymentTypeByCustomScript -ScriptType Powershell -ScriptContent "$($env:computername)" } else { " - There's no further deployment type defined for $($App.Name)." } } " - Adding $($App.Name) to DP $DistributionPointGroupName" Start-CMContentDistribution -ApplicationName $($App.Name) -DistributionPointGroupName $DistributionPointGroupName $CollectionName = "$($App.Name) Devices" " - Creating collection $CollectionName" New-CMDeviceCollection -Name "$CollectionName" -Comment "For deployemnt of $($App.Name)" -LimitingCollectionName "All Systems" -RefreshType Periodic -RefreshSchedule (New-CMSchedule -Start (get-date) -RecurInterval Days -RecurCount 7) -Verbose " - Adding members to the collection" $computer = "ICC-VPC145" # for testing Add-CMDeviceCollectionDirectMembershipRule -CollectionName "$CollectionName" -Resource (Get-CMDevice -Name $computer) -Verbose " - Making $($App.Name) $DeployAction $DeployPurpose to $CollectionName" Start-CMApplicationDeployment -CollectionName $CollectionName -Name $($App.Name) -DeployAction $DeployAction -DeployPurpose $DeployPurpose } "All application have been added from $Path" |
Here is the XML file that I used for testing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
<Applications> <Application> <Name>Notepad++ 6.7.4</Name> <Description>Replacement for notepad.exe</Description> <Manufacturer>Notepad++</Manufacturer> <SoftwareVersion>6.7.4</SoftwareVersion> <AutoInstall>true</AutoInstall> <DeploymentTypes> <DeploymentType> <MsiInstaller>true</MsiInstaller> <AutoIdentifyFromIntallationFile>true</AutoIdentifyFromIntallationFile> <InstallationFileLocation>\\My-Server\My-Share\Notepad++6.7.4\npp.6.7.4.installer.msi</InstallationFileLocation> <InstallationProgram>msiexec /i "npp.6.7.4.installer.msi" /l*v C:\Logs\npp_6_7_4_Install.log /q</InstallationProgram> <InstallationBehaviorType>InstallForSystem</InstallationBehaviorType> <LogonRequirementType>WhereOrNotUserLoggedOn</LogonRequirementType> </DeploymentType> </DeploymentTypes> </Application> <Application> <Name>Google Chrome 44</Name> <Description>Google Chrome internet browser</Description> <Manufacturer>Google</Manufacturer> <SoftwareVersion>44.0.2403.130</SoftwareVersion> <AutoInstall>true</AutoInstall> <DeploymentTypes> <DeploymentType> <ScriptInstaller>true</ScriptInstaller> <DeploymentTypeName>Install Google Chrome 44 x86</DeploymentTypeName> <InstallationProgram>msiexec /i googlechromestandaloneenterprise.msi TRANSFORMS=MSI_Google_Chrome_32bit_44_0_2403_130.mst /l*v C:\Logs\MSI_Google_Chrome_32bit_44_0_2403_130_Install.log /qn</InstallationProgram> <ContentLocation>\\My-Server\My-Share\MSI_Google_Chrome_44_0_2403_130\Deliverables\x86\</ContentLocation> <InstallationBehaviorType>InstallForSystem</InstallationBehaviorType> <LogonRequirementType>WhereOrNotUserLoggedOn</LogonRequirementType> </DeploymentType> </DeploymentTypes> </Application> <Application> <Name>Mozilla Firefox 40</Name> <Description>Mozilla Firefox internet browser</Description> <Manufacturer>Mozilla</Manufacturer> <SoftwareVersion>40.0</SoftwareVersion> <AutoInstall>true</AutoInstall> <DeploymentTypes> <DeploymentType> <MsiInstaller>true</MsiInstaller> <InstallationFileLocation>\\My-Server\My-Share\MSI_Mozilla_Firefox_40_0\Deliverables\MSI_Mozilla_Firefox_40_0.msi</InstallationFileLocation> <InstallationProgram>msiexec /i MSI_Mozilla_Firefox_40_0.msi /l*v C:\Logs\MSI_Mozilla_Firefox_40_0_Install.log /q</InstallationProgram> <InstallationBehaviorType>InstallForSystem</InstallationBehaviorType> <LogonRequirementType>WhereOrNotUserLoggedOn</LogonRequirementType> </DeploymentType> </DeploymentTypes> </Application> </Applications> |