forked from Ccmexec/MEMCM-OSD-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoDistributePackage.ps1
68 lines (51 loc) · 2.5 KB
/
AutoDistributePackage.ps1
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
<#
Scipt: AutoDistributePackages.ps1
Version: 1.0
Author: Johan Schrewelius, Onevinn AB
Date: 2017-03-05
Usage: Invoke by SCCM Status Filter Rule to automatically Distribute new Packages.
Status Message ID: 30000
Command: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -executionpolicy bypass -file "<Path to script>\AutoDistributePackages.ps1" %msgis02
Limitations: Designed to run on Primary Site Server (SMS Provider).
Config:
$CopyToShare = [$True | $False] - If package should be marked "Copy the content in this package to a package share....."
$DPgroups = [@() = Don't distribute content] | @("<Name of Distribution Point Group 1>", "<Name of Distribution Point Group 2>") = List of Distribution point GROUPS]
#>
Param(
[string]$PackageID
)
# CONFIG START
$CopyToShare = $True
$DPgroups = @("All DP")
# CONFIG END
import-module $env:SMS_ADMIN_UI_PATH.Replace("bin\i386","bin\ConfigurationManager.psd1") -force
$SiteCode = $(Get-WMIObject -ComputerName “$ENV:COMPUTERNAME” -Namespace “root\SMS” -Class “SMS_ProviderLocation”).SiteCode
new-psdrive -Name $SiteCode -PSProvider “AdminUI.PS.Provider\CMSite” -Root “$ENV:COMPUTERNAME” -Description “SCCM Primary Site”
Set-Location “$SiteCode`:”
$CMPackage = Get-CMPackage -Id $PackageID
$CMDriverPackage = Get-CMDriverPackage -Id $PackageID
$CMOSImage = Get-CMOperatingSystemImage -Id $PackageID
if($CMPackage) {
if($CopyToShare) {
$result = Set-CMPackage -Id $PackageID -CopyToPackageShareOnDistributionPoints $True -ErrorAction SilentlyContinue
}
$DPgroups |% {
$result = Start-CMContentDistribution –PackageID $PackageID –DistributionPointGroupName "$_" -ErrorAction SilentlyContinue
}
}
if($CMDriverPackage) {
if($CopyToShare) {
$result = Set-CMDriverPackage -Id $PackageID -CopyToPackageShareOnDistributionPoints $True -ErrorAction SilentlyContinue
}
$DPgroups |% {
$result = Start-CMContentDistribution -DriverPackageId $PackageID –DistributionPointGroupName "$_" -ErrorAction SilentlyContinue
}
}
if($CMOSImage) {
if($CopyToShare) {
$result = Set-CMOperatingSystemImage -Id $PackageID -CopyToPackageShareOnDistributionPoints $True -ErrorAction SilentlyContinue
}
$DPgroups |% {
$result = Start-CMContentDistribution -OperatingSystemImageId $PackageID –DistributionPointGroupName "$_" -ErrorAction SilentlyContinue
}
}