Kaido Jarvemets - Logo

Create 7 ZIP Application using PowerShell

Introduction

I have been presenting and building automated solutions for Configuration Manager for many years. If you are a Configuration Manager administrator, automating your day-to-day activities is super important. Most of the activities we need to carry out each day are the same daily and weekly basis. As a Configuration Manager administrator, I need to save time, and then I can focus on other important tasks such as Client Health, Compliance, etc.

The good thing about Configuration Manager is that we have a built-in PowerShell module and can automate anything. In this post, I will show you how you can create a 7-ZIP Application using the Configuration Manager PowerShell module

Requirements

  • Configuration Manager Admin Console
  • Permissions to create Application / Packages

How to Create a 7-ZIP Application

On your Primary Site server or your machine where the console is installed, execute the following commands to import the module.

				
					#STEP 0 - Import the Module
Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
$SiteCode = Get-PSDrive -PSProvider CMSITE
Set-Location "$($SiteCode.Name):\"
				
			

In our next step, we are going to download the 7-ZIP version 22.01 using the Invoke-WebRequest command and save it under our source folder

				
					<#
    =================================================================================
    DISCLAIMER:
    This script is provided "as-is" with no warranties. Usage of this script is at
    your own risk. The author is not liable for any damages or losses arising from
    using this script. Please review the full legal disclaimer at:
    https://kaidojarvemets.com/legal-disclaimer/
    =================================================================================
#>
#STEP 1 - Download the content
$7ZIPURL = 'https://www.7-zip.org/a/7z2201-x64.exe'
$SourceFolder = 'F:\Sources\Software\7-ZIP\22.01\X64\EXE\7z2201-x64.exe'
Invoke-WebRequest -Uri $7ZIPURL -OutFile $SourceFolder 
				
			

Now that we have the source files, we can read out the version info using the Get-Item command and prepare additional variables for the application creation.

				
					<#
    =================================================================================
    DISCLAIMER:
    This script is provided "as-is" with no warranties. Usage of this script is at
    your own risk. The author is not liable for any damages or losses arising from
    using this script. Please review the full legal disclaimer at:
    https://kaidojarvemets.com/legal-disclaimer/
    =================================================================================
#>
#STEP 2 - Get the file information
$FileInfo = Get-Item -Path $SourceFolder
$Version = $FileInfo.VersionInfo.ProductVersion
$FileName = $FileInfo.BaseName

#Define additional variables for 7-ZIP Application
$ApplicationName = '7-ZIP'
$CommandLine = "$($FileInfo.Name) /S"
$DeploymentTypeName = "Install - $FileName"
$ContentLocation = '\\cm01\sources\Software\7-ZIP\22.01\X64\EXE'
$DistributionPointGroupName = 'All Content'
$InstallCollectionName = "SWD - $ApplicationName - $Version"
$LimitingCollectionName = 'All Systems'
$SoftwareAPPRootFolder = "$($SiteCode.Name):\DeviceCollection\Software"
				
			

Create the application using the New-CMApplication command let.

				
					<#
    =================================================================================
    DISCLAIMER:
    This script is provided "as-is" with no warranties. Usage of this script is at
    your own risk. The author is not liable for any damages or losses arising from
    using this script. Please review the full legal disclaimer at:
    https://kaidojarvemets.com/legal-disclaimer/
    =================================================================================
#>
#STEP 3 - Create the Application
    $AppProperties = @{
        Name = $ApplicationName;
        SoftwareVersion = $Version
    }

New-CMApplication @AppProperties
				
			

Before we move on with the Deployment Types, we need to create detection methods. You can create the deployment methods using the New-CMDetectionClauseDirectory and New-CMDetectionClauseFile commands. These are just examples for you.

				
					<#
    =================================================================================
    DISCLAIMER:
    This script is provided "as-is" with no warranties. Usage of this script is at
    your own risk. The author is not liable for any damages or losses arising from
    using this script. Please review the full legal disclaimer at:
    https://kaidojarvemets.com/legal-disclaimer/
    =================================================================================
#>
#STEP 4 - Create the Detection Methods
    $7ZIPFolderProperties = @{
        DirectoryName = '7-Zip';
        Path = 'C:\Program Files\';
        Is64Bit = $True;
        Existence = $True
    }
    $7ZIPFileProperties = @{
        FileName = '7zFM.exe';
        Path = 'C:\Program Files\7-Zip';
        Is64Bit = $True;
        PropertyType = 'Version';
        ExpectedValue = $Version;
        ExpressionOperator = 'IsEquals'
        Value = $True
    }

$7ZIPFolder = New-CMDetectionClauseDirectory @7ZIPFolderProperties
$7ZIPFile = New-CMDetectionClauseFile @7ZIPFileProperties
				
			

So now that we have the application object and detection methods, we can create the Deployment Type.

				
					<#
    =================================================================================
    DISCLAIMER:
    This script is provided "as-is" with no warranties. Usage of this script is at
    your own risk. The author is not liable for any damages or losses arising from
    using this script. Please review the full legal disclaimer at:
    https://kaidojarvemets.com/legal-disclaimer/
    =================================================================================
#>
#STEP 5 - Create the Deployment Type with detection methods
$DeploymentTypeProperties = @{
    InstallCommand = $CommandLine
    DeploymentTypeName = $DeploymentTypeName
    ApplicationName = $ApplicationName
    ContentLocation = $ContentLocation
    AddDetectionClause = $7ZIPFolder,$7ZIPFile
}
Add-CMScriptDeploymentType @DeploymentTypeProperties
				
			

To distribute the content to the Distribution Point Groups, use the Start-CMContentDistribution command.

				
					<#
    =================================================================================
    DISCLAIMER:
    This script is provided "as-is" with no warranties. Usage of this script is at
    your own risk. The author is not liable for any damages or losses arising from
    using this script. Please review the full legal disclaimer at:
    https://kaidojarvemets.com/legal-disclaimer/
    =================================================================================
#>
#STEP 6 - Distribute the Content
    $ContentProperties = @{
        ApplicationName = $ApplicationName
        DistributionPointGroupName = $DistributionPointGroupName
    }
Start-CMContentDistribution @ContentProperties
				
			

Finally, we can create the collections and deployments.

				
					<#
    =================================================================================
    DISCLAIMER:
    This script is provided "as-is" with no warranties. Usage of this script is at
    your own risk. The author is not liable for any damages or losses arising from
    using this script. Please review the full legal disclaimer at:
    https://kaidojarvemets.com/legal-disclaimer/
    =================================================================================
#>
#STEP 7 - Create the Collection
    $CollectionProperties = @{
        Name = $InstallCollectionName;
        LimitingCollectionName = $LimitingCollectionName;
        CollectionType = 'Device'
    }
New-CMCollection @CollectionProperties | Move-CMObject -FolderPath $SoftwareAPPRootFolder

#STEP 8 - Create the Deployment
    $DeploymentProperties = @{
        Name = $ApplicationName;
        DeployAction = 'Install';
        DeployPurpose = 'Required';
        CollectionName = $InstallCollectionName
    }
New-CMApplicationDeployment @DeploymentProperties
				
			

Summary

As you see from this example, we can build end-to-end automated solutions. We can save a lot of time. We need to take the time and invest in it.

You can download the full copy from here – Configuration-Manager/Create-7ZIPApplication.ps1 at master · Kaidja/Configuration-Manager (github.com)

Leave a Reply

Contact me

If you’re interested in learning about Create 7 ZIP Application using PowerShell. I can help you understand how this solution can benefit your organization and provide a customized solution tailored to your specific needs.

Table of Contents