Distribute multiple packages on multiple distribution points

Hello Guys, Hope you are doing well. Today we are going to automate the package distribution.

This script will help you to distribute multiple packages on multiple distribution points.

let's download the PowerShell code mentioned below and run it from any SMS Provider server.


Distribute Multiple packages on multiple distribution points



<#

    .SYNOPSIS

    Distribute multiple packages to multiple distribution points.

    .DESCRIPTION

    This PowerShell will help you to Distribute Multiple packages on multiple Distribution Points on

    Single click. To use this Script you need to create TWO text files(1.packages.txt 2.DPs.txt) to

    provide as an input to the script 

    .NOTES

    =============================================================================================================================================

    Created with:     Windows PowerShell ISE

    Created on:       Saturday, September 25, 2021 6:37:17 PM

    Created by:       Dashrath Chate

    Organization:     Blogger.com

    =============================================================================================================================================

#>

#load assemblies

Add-Type -AssemblyName System.Windows.forms

Add-Type -AssemblyName System.Drawing

$form = New-Object System.Windows.Forms.Form

$form.Text = "DC-SCCM Package Management"

$form.Size = New-Object System.Drawing.Size(800,600)

$form.MaximizeBox = $false

$InputSCode = new-object System.Windows.Forms.TextBox

$InputSCode.Location =New-Object System.Drawing.Size(630,70)

$InputSCode.AutoSize=$true

$form.Controls.Add($InputSCode)

$SCode = $InputSCode.Text

$InputSMSName = new-object System.Windows.Forms.TextBox

$InputSMSName.Location =New-Object System.Drawing.Size(630,140)

$InputSMSName.AutoSize=$true

$form.Controls.Add($InputSMSName)

$SMSProvider = $InputSMSName.Text


Function Pkg()

{  

    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog

    $OpenFileDialog.ShowHelp = $True

    $OpenFileDialog.filter = "Text Files (*.txt)| *.txt"

    $OpenFileDialog.ShowDialog() 

    $PkgFile = $OpenFileDialog.FileName

    $InputPkg.Text = $PkgFile

}

Function DPs()

{

    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog

    $OpenFileDialog.ShowHelp = $True

    $OpenFileDialog.filter = "Text Files (*.txt)| *.txt"

    $OpenFileDialog.ShowDialog() 

    $DPsFile = $OpenFileDialog.FileName

    $InputDPs.Text = $DPsFile

}

Function Submit()

{

$SiteCode = $SCode

$ProviderMachineName = $SMSProvider

$initParams = @{}

if((Get-Module ConfigurationManager) -eq $null) {

    Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" @initParams 

}

if((Get-PSDrive -Name $SiteCode -PSProvider CMSite -ErrorAction SilentlyContinue) -eq $null) {

    New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName @initParams

}

Set-Location "$($SiteCode):\" @initParams


                $Pkg = Get-Content -Path $InputPkg.Text

                $DPs = Get-Content -path $InputDPs.Text


                    Foreach($Pkg in $Pkg)

                    {

                        Foreach($DPs in $DPs)

                        {

                        Start-CMContentDistribution -DeploymentPackageId $Pkg -DistributionPointName $DPs

                        }

                    }

}

$InputPkg = new-object System.Windows.Forms.TextBox

$InputPkg.Location =New-Object System.Drawing.Size(20,70)

$InputPkg.Size = New-Object System.Drawing.Size(300,50)

$form.Controls.Add($InputPkg)


$InputDPs = new-object System.Windows.Forms.TextBox

$InputDPs.Location =New-Object System.Drawing.Size(20,230)

$InputDPs.Size = New-Object System.Drawing.Size(300,50)

$form.Controls.Add($InputDPs)

$lPkg = New-Object System.Windows.Forms.Label

$lPkg.Text = "Click on Browse and Provide Package's File Path"

$lPkg.Location =New-Object System.Drawing.Size(20,40)

$lPkg.BackColor = "Transparent"

$lPkg.AutoSize = $true

$form.Controls.Add($lPkg)


$lDPs = New-Object System.Windows.Forms.Label

$lDPs.Text = "Click on Browse and Provide Distribution Point's File Path"

$lDPs.Location =New-Object System.Drawing.Size(20,200)

$lDPs.BackColor = "Transparent"

$lDPs.AutoSize = $true

$form.Controls.Add($lDPs)


$LSiteCode = New-Object System.Windows.Forms.Label

$LSiteCode.Text = "SITE CODE"

$LSiteCode.Location =New-Object System.Drawing.Size(630,50)

$LSiteCode.BackColor = "Transparent"

$LSiteCode.AutoSize = $true

$form.Controls.Add($LSiteCode)

$LSMSProvider = New-Object System.Windows.Forms.Label

$LSMSProvider.Text = "SMS PROVIDER"

$LSMSProvider.Location =New-Object System.Drawing.Size(630,120)

$LSMSProvider.BackColor = "Transparent"

$LSMSProvider.AutoSize = $true

$form.Controls.Add($LSMSProvider)


$lAbout = New-Object System.Windows.Forms.Label

$lAbout.Text = "This PowerShell will help you to Distribute Multiple packages on multiple Distribution Points on

Single click. To use this Script you need to create TWO text files(1.packages.txt 2.DPs.txt) to

provide as an input to the script"

$lAbout.Location =New-Object System.Drawing.Size(10,420)

$lAbout.BackColor = "Transparent"

$lAbout.AutoSize = $true

$form.Controls.Add($lAbout)


#Creating Button

$BPkg = New-Object System.Windows.Forms.Button

$BPkg.Location = New-Object System.Drawing.Size(350,90)

$BPkg.AutoSize = $True

$BPkg.Text = "Browse File"

$form.Controls.Add($BPkg)

$BPkg.add_Click({Pkg})


$BDPs = New-Object System.Windows.Forms.Button

$BDPs.Location = New-Object System.Drawing.Size(350,250)

$BDPs.AutoSize = $True

$BDPs.Text = "Browse File"

$form.Controls.Add($BDPs)

$BDPs.add_Click({DPs})


$Submit = New-Object System.Windows.Forms.Button

$Submit.Location = New-Object System.Drawing.Size(410,350)

$Submit.AutoSize = $True

$Submit.Text = "Submit"

$form.Controls.Add($Submit)

$Submit.add_Click({Submit})

$Exit = New-Object System.Windows.Forms.Button

$Exit.Location = New-Object System.Drawing.Size(520,350)

$Exit.AutoSize = $True

$Exit.Text = "Exit"

$form.Controls.Add($Exit)

$Exit.add_Click({$form.Close()})

$FeedBack = New-Object System.Windows.Forms.Button

$FeedBack.Location = New-Object System.Drawing.Size(630,350)

$FeedBack.AutoSize = $True

$FeedBack.Text = "FeedBack"

$form.Controls.Add($FeedBack)

$FeedBack.Add_Click({[system.Diagnostics.Process]::start("https://dashrathchate.blogspot.com/p/contact-us.html")})

$GPkg= New-Object System.Windows.Forms.GroupBox

$GPkg.Location = New-Object System.drawing.Size(10,10)

$GPkg.Size = New-Object System.Drawing.Size (600,150)

$GPkg.Text ="Package"

$form.Controls.Add($GPkg)

$GBDPs= New-Object System.Windows.Forms.GroupBox

$GBDPs.Location = New-Object System.drawing.Size(10,170)

$GBDPs.Size = New-Object System.Drawing.Size (600,150)

$GBDPs.Text ="Distrubution Point"

$form.Controls.Add($GBDPs)

$GBAbout= New-Object System.Windows.Forms.GroupBox

$GBAbout.Location = New-Object System.drawing.Size(10,400)

$GBAbout.Size = New-Object System.Drawing.Size (750,130)

$GBAbout.Text ="About"

$form.Controls.Add($GBAbout)

$GBAInfo= New-Object System.Windows.Forms.GroupBox

$GBAInfo.Location = New-Object System.drawing.Size(625,20)

$GBAInfo.Size = New-Object System.Drawing.Size (135,200)

$GBAInfo.Text ="Additional Info"

$form.Controls.Add($GBAInfo)

$form.ShowDialog()

_____________________________________________________________________


No comments:

Post a Comment

Leave your valuable words here for improve better.