Last active
January 27, 2016 14:22
-
-
Save vannmangel/2a9066a7df4fa6ec8c02 to your computer and use it in GitHub Desktop.
SCCM 2012 R2 - Fetches the PackageID from all applications, packages, boot images, OS images and driver packages and puts them in a DP group.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -version 3 | |
<# | |
.NOTES | |
=========================================================================== | |
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.95 | |
Created on: 28.10.2015 16.18 | |
Created by: Stian Myhre (including some "stealing with pride" from Kaido Järvemets, CoreTech) | |
Organization: Amedia Teknologi | |
Filename: Add-AllPackageIDsToDistributionPointGroup.ps1 | |
=========================================================================== | |
.DESCRIPTION | |
Fetches the PackageID from all applications, packages, boot images, OS images and driver packages and puts them in a DP group. | |
#> | |
Function Add-AllPackageIDsToDistributionPointGroup | |
{ | |
[CmdLetBinding()] | |
Param ( | |
[Parameter(Mandatory = $True, HelpMessage = "Enter ConfigMgr site code")] | |
$SiteCode, | |
[Parameter(Mandatory = $True, HelpMessage = "Enter site server name")] | |
$SiteServer, | |
[Parameter(Mandatory = $True, HelpMessage = "Enter Distribution Point Group name")] | |
$DPGroup, | |
[Parameter(Mandatory = $false, HelpMessage = "Import ConfigMgr module from default installation path")] | |
[Switch]$UseDefaultModulePath, | |
[Parameter(Mandatory = $false, HelpMessage = "Specify the path to ConfigMgr module")] | |
$CMModulePath | |
) | |
#Import the module | |
if ($UseDefaultModulePath) | |
{ | |
Import-Module -Name "${env:ProgramFiles(x86)}\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1" | |
} | |
if ($CMModulePath) | |
{ | |
Import-Module -Name $CMModulePath | |
} | |
#Verify ConfigMgr module existence | |
$CMModule = Get-Module ConfigurationManager | |
if ($CMModule.Name -eq "ConfigurationManager") | |
{ | |
#Connect to Site Code PSDrive | |
Set-Location ($sitecode + ':\') | |
#Fetch the PackageIDs | |
Get-CMApplication | select PackageID -OutVariable Applications | |
Get-CMPackage | select PackageID -OutVariable Package | |
Get-CMBootImage | select PackageID -OutVariable BootImage | |
Get-CMOperatingSystemImage | select PackageID -OutVariable OSImage | |
Get-CMDriverPackage | select PackageID -OutVariable DriverPackage | |
#Merge the PackageIDs | |
$allpackages = ($Applications.PackageID + $Package.PackageID + $BootImage.PackageID + $OSImage.PackageID + $DriverPackage.PackageID) | |
#Add the PackageIDs to DP group | |
foreach ($PackageID in $allpackages) | |
{ | |
#A special thanks to Kaido Järvemets in CoreTech for this code :) | |
Try | |
{ | |
$DPGroupQuery = Get-WmiObject -Namespace "Root\SMS\Site_$SiteCode" -Class SMS_DistributionPointGroup -ComputerName $SiteServer ` | |
-ErrorAction STOP -Filter "Name='$DPGroup'" | |
$DPGroupQuery.AddPackages($PackageID) | |
} | |
Catch | |
{ | |
$_.Exception.Message | |
} | |
} | |
} | |
else #error handling | |
{ | |
Write-Output 'Oops, seems like the ConfigurationManager module was not imported correctly.' | |
Break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment