forked from DexterPOSH/PS_ConfigMgr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TechnetAdd-SCCMDPContent.ps1
95 lines (82 loc) · 3.38 KB
/
TechnetAdd-SCCMDPContent.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
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
function Add-SCCMDPContent
{
<#
.Synopsis
Function to Add Packages to the DP
.DESCRIPTION
THis Function will connect to the SCCM Server SMS namespace and then Add the Package IDs
passed to the Function for the specified DP name.
.EXAMPLE
PS> Add-SCCMDPContent -PackageID DEX123AB,DEX145CD -DPname DexDP -Computername DexSCCMServer
This will remove the Packages with Package IDs [ DEX123AB,DEX145CD] from the Distribution Point "DexDP".
.INPUTS
System.String[]
.OUTPUTS
System.Management.Automation.PSCustomObject
.NOTES
Author - DexterPOSH (Deepak Singh Dhami)
#>
[CmdletBinding()]
[OutputType([PSObject])]
Param
(
# Specify the Package IDs which need to be removed from the DP
[Parameter(Mandatory,
ValueFromPipelineByPropertyName,
Position = 0)]
[string[]]$PackageID,
# Pass the DP name where cleanup is to be done
[Parameter(Mandatory = $true)]
[String]$DPName,
#Supply the SCCM Site Server hosting SMS Namespace Provider
[Parameter()]
[Alias('SCCMServer')]
[String]$ComputerName
)
Begin
{
Write-Verbose -Message '[BEGIN] Starting the Function'
try
{
$sccmProvider = Get-WmiObject -Query 'select * from SMS_ProviderLocation where ProviderForLocalSite = true' -Namespace 'root\sms' -ComputerName $ComputerName -ErrorAction Stop
# Split up the namespace path
$Splits = $sccmProvider.NamespacePath -split '\\', 4
$NALPath = '["Display=\\{0}\"]MSWNET:["SMS_SITE={1}"]\\{0}\' -f $sccmProvider.Machine,$sccmProvider.SiteCode
Write-Verbose -Message "Provider is located on $($sccmProvider.Machine) in namespace $($splits[3])"
# Create a new hash to be passed on later
$hash = @{'ComputerName' = $ComputerName;'NameSpace' = $Splits[3];'ErrorAction' = 'Stop'}
$WMIClass = Get-WmiObject -Class = 'SMS_DistributionPoint' -List @hash
}
catch
{
Write-Warning -Message 'Something went wrong while getting the SMS ProviderLocation or SMS_DistributionPoint Class Object'
throw $Error[0].Exception
}
}
Process
{
Write-Verbose -Message "[PROCESS] Working to add packages to DP --> $DPName "
#get all the packages in the Distribution Point
foreach ($ID in $PackageID)
{
TRY {
if (Get-WmiObject -Query "Select PackageID from SMS
$newInstance = $WMIClass.createInstance()
$newinstance.PackageID = $ID
$newinstance.ServerNALPath = $NALPath
$newinstance.SiteCode = $sccmProvider.sitecode
$newinstance.put()
}
CATCH
{
Write-Warning -Message "[PROCESS] Something went wrong while adding the Package with PackageID $ID from $DPname"
Throw $_.exception
}
}#End Foreach-Object
}#End Process
End
{
Write-Verbose -Message '[END] Ending the Function'
}
}