Category filter
Script to install/uninstall packages on Windows
Users normally download and install software packages (or software upgrades) from the download links available on websites. Because it is tedious enough to trawl countless websites to get the packages, Windows offers a package manager solution named Windows Package Manager to help us install and manage different software packages from the command line. It is a faster and more seamless method for installing packages. Users can create scripts using the commands contained in the PacketManagement module to install packages on their Windows devices. Hexnode UEM offers IT admins the Execute Custom Script action to remotely deploy these scripts to their Windows 10/11 devices. This action allows for packages to be downloaded and installed on devices without the need for user intervention.
PowerShell script to install package
1 |
Install-Package -Name Name of the package to be installed -Source Name of the package source -Force |
The script uses the Install-Package
cmdlet with two parameters, Name
and Source
, to install a software package. Name
is used to specify the name of the package, while Source
specifies the name of the source/repository where the package is stored.
For example, the script looks like this when installing the Carbon
app from the package source PSGallery
:
Install-Package -Name Carbon -Source PSGallery –Force
Because the packages are stored in repositories called package sources, you could use the Get-PackageSource
command to get the complete list of package sources that are available for the endpoint.
PowerShell script to find a software package and install it
1 |
Find-Package “Name of the package to be installed” | Install-Package |
The Find-Package
cmdlet is used to find software packages in available package sources. Admin must specify the name of the package in the command to achieve this. The Install-Package
cmdlet then installs the found package.
For example, the following sample script installs a package named Gac
by piping the package fetched using the Find-Package
command:
Find-Package “Gac” | Install-Package
PowerShell script to install packages by specifying a range of versions
1 |
Install-Package -Name “Name of package to be installed” -MinimumVersion Minimum Version number –MaximumVersion Maximum Version number |
To give an example, we can install the latest version of the Az.Billing
package among a range of versions by specifying the MinimumVersion
and MaximumVersion
parameters in the Install-Package
cmdlet:
Install-Package -Name “Az.Billing” -MinimumVersion 1.0.1 -MaximumVersion 1.0.3
PowerShell script to uninstall package
1 |
Uninstall-Package -Name Name of the package to be uninstalled |
For uninstallation of a package, use the Uninstall-Package
cmdlet and specify the name of the package.
To give an example, Carbon
app can be uninstalled from the device using the command:
Uninstall-Package -Name Carbon