### Install Chocolatey Package Example Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/chocolatey-install-ps1.mdx This example demonstrates how to use the Install-ChocolateyPackage helper to download and silently install an MSI package. Ensure the correct URLs and silent arguments are provided. ```powershell $name = 'StExBar' $url = 'http://stexbar.googlecode.com/files/StExBar-1.8.3.msi' $url64 = 'http://stexbar.googlecode.com/files/StExBar64-1.8.3.msi' $silent = '/quiet' Install-ChocolateyPackage $name 'msi' $silent $url $url64 ``` -------------------------------- ### Install Command Examples Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/choco/commands/install.mdx Common usage patterns for installing packages, including force flags, parameters, and source specifications. ```text choco install sysinternals choco install notepadplusplus googlechrome atom 7zip choco install notepadplusplus --force --force-dependencies choco install notepadplusplus googlechrome atom 7zip -dvfy choco install git -y --params="'/GitAndUnixToolsOnPath /NoAutoCrlf'" choco install git -y --params="'/GitAndUnixToolsOnPath /NoAutoCrlf'" --install-arguments="'/DIR=C:\git'" # Params are package parameters, passed to the package # Install args are installer arguments, appended to the silentArgs # in the package for the installer itself choco install nodejs.install --version 0.10.35 choco install git -s "'https://somewhere/out/there'" choco install git -s "'https://somewhere/protected'" -u user -p pass ``` -------------------------------- ### Install Packages via Puppet Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/choco/setup.mdx Examples of installing single or multiple packages with specific versions, sources, or install options. ```puppet package {'roundhouse': ensure => '0.8.5.0', } package {'git': ensure => latest, } package {'launchy': ensure => installed, install_options => ['--override', '--installArgs','"', '/VERYSILENT','/NORESTART','"'], } package {['virustotaluploader', 'googlechrome', 'notepadplusplus', '7zip', 'ruby', 'charles', 'grepwin', 'stexbar', 'inkscape', 'gitextensions', 'pandoc', 'snagit', 'nodejs', ]: ensure => latest, source => 'https://community.chocolatey.org/api/v2/', } package {'screentogif': ensure => '2.2.160907', source => 'https://community.chocolatey.org/api/v2/', } package {'dotnet4.5.2': ensure => latest, } ``` -------------------------------- ### List Installed Templates Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/create/commands/template.mdx Examples demonstrating how to list installed templates. The command can be used with or without the `list` keyword. Options like `--reduce-output` and `--verbose` can modify the output. ```bash choco template ``` ```bash choco templates ``` ```bash choco template list ``` ```bash choco template list --reduce-output ``` ```bash choco template list --verbose ``` -------------------------------- ### Define Ansible Task for Client Setup Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/c4b-environments/ansible/client-setup.mdx Example structure for an Ansible task to initiate the client setup process. ```yaml --- - name: Chocolatey For Business Client Setup hosts: "{{ c4b_nodes }}" gather_facts: true vars_prompt: - name: ccm_fqdn prompt: "FQDN to access Chocolatey Central Management, e.g. ccm.example.com" private: no - name: ccm_client_salt ``` -------------------------------- ### Begin C4B Setup Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/c4b-environments/quick-start-environment/chocolatey-for-business-quick-start-guide.mdx Run this in an elevated PowerShell console to prepare the environment for C4B installation. ```powershell Set-ExecutionPolicy Bypass -Scope Process -Force [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::tls12 Invoke-RestMethod https://ch0.co/qsg-go | Invoke-Expression ``` -------------------------------- ### Create a new package with silent arguments and URL Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/create/commands/new.mdx This example shows how to provide silent installation arguments and a URL for the package installer. ```bash choco new bob silentargs="'/S'" url="'https://somewhere/out/there.msi'" ``` -------------------------------- ### Install Package with Parameters Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/guides/create/parse-packageparameters-argument.mdx Example of how to pass parameters to a Chocolatey package during installation using the --params argument. ```powershell choco install packageID [other options] --params="'/ITEM:value /ITEM2:value2 /FLAG_BOOLEAN'" ``` -------------------------------- ### Install Chocolatey Client with License File Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/guides/organizations/organizational-deployment-guide/client-setup.mdx Install the Chocolatey client and configure background services by downloading the setup script from GitHub and providing a local path to your Chocolatey For Business license file. ```powershell & [scriptblock]::Create([System.Net.WebClient]::new().DownloadString( "https://raw.githubusercontent.com/chocolatey/choco-orgguide-scripts/refs/heads/main/ClientSetup.ps1" )) -LicensePath ~\Downloads\chocolatey.license.xml ``` -------------------------------- ### Create chocolateyInstall.ps1 for MSI installers Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/create/create-packages-quick-start.mdx Example script for installing an MSI package with support for 32-bit/64-bit URLs and custom exit codes. ```powershell $packageName = 'Package Name' $installerType = 'msi' $url = 'http://path/to/download/installer_x86.msi' $url64 = 'http://path/to/download/installer_x64.msi' $silentArgs = '/quiet' $validExitCodes = @(0,3010) Install-ChocolateyPackage $packageName $installerType $silentArgs $url $url64 -validExitCodes $validExitCodes ``` -------------------------------- ### Apply Custom Configuration Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/c4b-environments/quick-start-environment/advanced-client-configuration.mdx Apply custom settings during installation with the `-AdditionalConfiguration` parameter. This example sets the `centralManagementReportPackagesTimerIntervalInSeconds` to 6 hours. ```powershell Set-Location /path/to/register-c4bendpoint.ps1 . .\Register-C4bEndpoint.ps1 -RepositoryCredential (Get-Credential) -AdditionalConfiguration @{ 'centralManagementReportPackagesTimerIntervalInSeconds' = '21600'} ``` -------------------------------- ### Download and Install Chocolatey Client Setup Script Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/guides/organizations/organizational-deployment-guide/client-setup.mdx Use this PowerShell script to download and execute the client setup script. It configures Chocolatey CLI, Chocolatey Agent, and Chocolatey Central Management. Ensure you replace placeholder values with your actual environment details. ```powershell $ScriptArgs = @{ RepositoryUrl = "OrgGuideCoreRepositoryUrl" RepositoryCredential = [PSCredential]::new( "OrgGuideRepoUserName", (ConvertTo-SecureString "OrgGuideRepoUserPassword" -AsPlainText -Force) ) ChocolateyCentralManagementUrl = "OrgGuideCcmUrl" ServiceCommunicationSalt = "OrgGuideCcmServiceSalt" ClientCommunicationSalt = "OrgGuideCcmClientSalt" } $WebClient = [System.Net.WebClient]::new() $WebClient.Credentials = $ScriptArgs.RepositoryCredential & ([scriptblock]::Create($WebClient.DownloadString( ($ScriptArgs.RepositoryUrl -replace '\/repository\/(?.+)\/index.json)?$', '/repository/choco-install/ClientSetup.ps1') ))) @ScriptArgs ``` -------------------------------- ### Pushing an Intune package with credentials Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/licensed-extension/intune/push.mdx Example of pushing a package by explicitly providing the source GUID and API credentials. ```powershell choco push firefox.86.0.intunewin --source= --api-key=: ``` -------------------------------- ### Install Chocolatey GUI Branding Template Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/features/branding.mdx Install the `chocolateygui-branding.template` package from the licensed feed to get started with creating a custom branding package. ```powershell choco install chocolateygui-branding.template -y ``` -------------------------------- ### Info Command Examples Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/choco/commands/info.mdx Examples of how to use the choco info command to get information on specific packages. This is useful for checking package details before installation. ```bash choco info chocolatey ``` ```bash choco info googlechrome ``` ```bash choco info powershell ``` -------------------------------- ### Install Package with Parameters Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/guides/create/parse-packageparameters-argument.mdx Demonstrates the basic syntax for installing a package with custom parameters. Ensure parameters are correctly quoted, especially when they contain spaces, as shell behavior can vary. ```powershell choco install --params "'/key:value key2:value'" ``` -------------------------------- ### Install a Chocolatey Package with Options Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/chocolatey-vs-ninite.mdx Installs a specified package using `Install-ChocolateyPackage`. This example demonstrates installing 'windirstat' with a silent install switch, a checksum, and a direct download URL. ```powershell Install-ChocolateyPackage 'windirstat' 'exe' '/S' 'https://windirstat.info/wds_current_setup.exe' -Checksum 123456 -ChecksumType 'sha256' ``` -------------------------------- ### Onboard Client via PowerShell Script Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/c4b-environments/ansible/client-setup.mdx A PowerShell script to download and execute the client setup process from a Nexus repository. ```powershell param( # The fully qualified domain name (FQDN) of the Sonatype Nexus Repository service [Parameter(Mandatory)] $FQDN, # The Password for the chocouser account on Sonatype Nexus Repository service [Parameter(Mandatory)] $Password, # The Chocolatey Central Management client communication salt, provided during deployment [Parameter(Mandatory)] $ClientCommunicationSalt, # The Chocolatey Central Management service communication salt [Parameter(Mandatory)] $ServiceCommunicationSalt ) $credential = [pscredential]::new('chocouser', ($Password | ConvertTo-SecureString -AsPlainText -Force)) $downloader = [System.Net.WebClient]::new() $downloader.Credentials = $credential $script = $downloader.DownloadString("https://$($FQDN):8443/repository/choco-install/ClientSetup.ps1") $params = @{ Credential = $credential ClientSalt = $clientCommunicationSalt ServerSalt = $serviceCommunicationSalt } & ([scriptblock]::Create($script)) @params ``` -------------------------------- ### Create chocolateyInstall.ps1 for EXE installers Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/create/create-packages-quick-start.mdx Example script for installing an executable package with silent arguments. ```powershell $name = 'Package Name' $installerType = 'exe' $url = 'http://path/to/download/installer.exe' $silentArgs = '/VERYSILENT' Install-ChocolateyPackage $name $installerType $silentArgs $url ``` -------------------------------- ### Install Package from Alternative Source Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/chocolatey-vs-ninite.mdx Demonstrates installing a package from an alternative source, such as Cygwin for 'bash'. ```powershell choco install bash --source cygwin ``` -------------------------------- ### Install Portable Packages Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/choco/setup.mdx Examples of installing portable software packages that do not require administrative privileges. ```powershell choco install puppet-agent.portable -y choco install ruby.portable -y choco install git.commandline -y # pick an editor #choco install visualstudiocode.portable -y # not yet available choco install notepadplusplus.commandline -y #choco install nano -y #choco install vim-tux.portable # What else can I install without admin rights? # https://community.chocolatey.org/packages?q=id%3Aportable ``` -------------------------------- ### Prepare the Vagrant environment Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/community-repository/moderation/package-verifier.mdx Initial setup commands to prepare the virtual machine for package testing. ```powershell Copy `PrepareMachine.ps1` to `VagrantAction.ps1` Run `vagrant up` Run `vagrant sandbox on` ``` -------------------------------- ### Install from Local File Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/choco/commands/install.mdx Syntax for installing directly from a local nuspec or nupkg file. ```text choco install choco install ``` -------------------------------- ### Perform Non-Administrative Chocolatey Installation Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/choco/setup.mdx Configures a custom installation directory and bypasses execution policy for a non-admin setup. ```powershell # Set directory for installation - Chocolatey does not lock # down the directory if not the default $InstallDir='C:\ProgramData\chocoportable' $env:ChocolateyInstall="$InstallDir" # If your PowerShell Execution policy is restrictive, you may # not be able to get around that. Try setting your session to # Bypass. Set-ExecutionPolicy Bypass -Scope Process -Force; # All install options - offline, proxy, etc at # https://chocolatey.org/install iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) ``` -------------------------------- ### Create Tutorials Directory Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/guides/create/prepare-packaging-env.mdx Execute this command in a PowerShell console to create a 'tutorials' directory in your user's home directory. ```powershell New-Item ~\tutorials -ItemType Directory ``` -------------------------------- ### Install Chocolatey Package with MSI Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/create/functions/install-chocolateyinstallpackage.mdx Installs a package using an MSI installer, specifying silent arguments and valid exit codes. This example uses a hashtable for arguments. ```powershell $packageName= 'bob' $toolsDir = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)" $fileLocation = Join-Path $toolsDir 'INSTALLER_EMBEDDED_IN_PACKAGE' $packageArgs = @{ packageName = $packageName fileType = 'msi' file = $fileLocation silentArgs = "/qn /norestart" validExitCodes= @(0, 3010, 1641) softwareName = 'Bob*' } Install-ChocolateyInstallPackage @packageArgs ``` -------------------------------- ### Install Package with Specific Parameters Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/guides/create/parse-packageparameters-argument.mdx Illustrates how to pass specific package parameters, including those with spaces, during installation. Note the shell-specific quoting required for paths with spaces. ```powershell # See NOTE below, shell affects the way to pass args when you need to include quotes choco install -d --package-parameters '/Port:82 /Edition:LicenseKey1 /InstallationPath:""C:\temp\folder with space"" /AdditionalTools' ``` -------------------------------- ### List Installed Packages Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/choco/commands/list.mdx Use `choco list -i` to list installed packages. This command requires no special setup. ```bash choco list -i ``` ```bash choco list --include-programs ``` -------------------------------- ### Install Command Usage Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/choco/commands/install.mdx General syntax for installing packages or a packages.config file. ```text choco install [ ] [] ``` -------------------------------- ### Initialize C4B Setup with Certificates Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/c4b-environments/quick-start-environment/chocolatey-for-business-quick-start-guide.mdx Execute the initialization script using different certificate configurations based on your environment requirements. ```powershell Set-Location "$env:SystemDrive\choco-setup\files" .\Initialize-C4bSetup.ps1 -Thumbprint '' ``` ```powershell Set-Location "$env:SystemDrive\choco-setup\files" .\Initialize-C4bSetup.ps1 -Thumbprint '' -CertificateDnsName '' ``` ```powershell Set-Location "$env:SystemDrive\choco-setup\files" .\Initialize-C4bSetup.ps1 -Thumbprint deee9b2fabb24bdaae71d82286e08de1 -CertificateDnsName chocolatey.foo.org ``` ```powershell Set-Location "$env:SystemDrive\choco-setup\files" .\Initialize-C4bSetup.ps1 ``` -------------------------------- ### Install Additional Packages with Chocolatey Client Setup Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/guides/organizations/organizational-deployment-guide/client-setup.mdx Install extra packages during the client setup by using the -AdditionalPackages parameter with an array of package definition hashtables. Each hashtable requires at least an 'Id', and can optionally include 'Version' and 'Pin' status. ```powershell .\ClientSetup.ps1 @ScriptArgs -AdditionalPackages @( @{ Id = 'firefox' Version = '144.0.0' Pin = $true } ) ``` -------------------------------- ### Install Chocolatey Package with MSI and Transform Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/create/functions/install-chocolateyinstallpackage.mdx Installs a package using an MSI installer with a transform file (.mst) specified in the silent arguments. This example uses a hashtable for arguments. ```powershell $packageName= 'bob' $toolsDir = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)" $fileLocation = Join-Path $toolsDir 'someinstaller.msi' $mstFileLocation = Join-Path $toolsDir 'transform.mst' $packageArgs = @{ packageName = $packageName fileType = 'msi' file = $fileLocation silentArgs = "/qn /norestart TRANSFORMS=`"$mstFileLocation`"" validExitCodes= @(0, 3010, 1641) softwareName = 'Bob*' } Install-ChocolateyInstallPackage @packageArgs ``` -------------------------------- ### Manage Configuration Settings Examples Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/chocolatey-gui/commands/config.mdx Common operations for listing, retrieving, updating, and removing configuration values. ```powershell chocolateyguicli config chocolateyguicli config list chocolateyguicli config get --name="'outdatedPackagesCacheDurationInMinutes'" chocolateyguicli config set --name="'outdatedPackagesCacheDurationInMinutes'" --value="'60'" chocolateyguicli config unset --name="'outdatedPackagesCacheDurationInMinutes'" ``` -------------------------------- ### Install Chocolatey Package with MSI and Custom Arguments Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/create/functions/install-chocolateyinstallpackage.mdx Installs a package using an MSI installer with custom silent arguments, including a property. This example uses a hashtable for arguments. ```powershell $packageName= 'bob' $toolsDir = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)" $fileLocation = Join-Path $toolsDir 'someinstaller.msi' $packageArgs = @{ packageName = $packageName fileType = 'msi' file = $fileLocation silentArgs = "/qn /norestart MSIPROPERTY=`"true`"" validExitCodes= @(0, 3010, 1641) softwareName = 'Bob*' } Install-ChocolateyInstallPackage @packageArgs ``` -------------------------------- ### Install Chocolatey Package with EXE Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/create/functions/install-chocolateyinstallpackage.mdx Installs a package using an EXE installer from a network share, specifying silent arguments and valid exit codes. This example uses a hashtable for arguments. ```powershell $packageArgs = @{ packageName = 'bob' fileType = 'exe' file = '\SHARE_LOCATION\to\INSTALLER_FILE' silentArgs = "/S" validExitCodes= @(0) softwareName = 'Bob*' } Install-ChocolateyInstallPackage @packageArgs ``` -------------------------------- ### Move Deployment Plan to Ready and Start Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/central-management/usage/api/examples.mdx Transitions a deployment plan to the 'Ready' state and then initiates its execution. This is the final step to start the deployment process. ```powershell $params = @{ Uri = "https://$CcmServerHostname/api/services/app/DeploymentPlans/MoveToReady" Method = "POST" WebSession = $Session ContentType = 'application/json' Body = @{ id = $deployment.Id } | ConvertTo-Json UseBasicParsing = $true } $null = Invoke-RestMethod @params $params = @{ Uri = "https://$CcmServerHostname/api/services/app/DeploymentPlans/Start" Method = "POST" WebSession = $Session ContentType = 'application/json' Body = @{ id = $deployment.Id } | ConvertTo-Json UseBasicParsing = $true } $null = Invoke-RestMethod @params ``` -------------------------------- ### Optimize Command Examples Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/choco/commands/optimize.mdx Common examples for running the optimize command with or without specific flags. ```shell choco optimize choco optimize --reduce-nupkg-only ``` -------------------------------- ### Define Meta Package Dependencies in Nuspec Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/guides/create/create-meta-package.mdx Use the dependencies section in the nuspec file to list packages that should be installed with this meta package. This example installs 'putty.portable'. ```xml meta-package 1.0.0 meta-package (Install) Chocolatey Software meta-package tutorial Tutorial for creating metapackages Tutorial for creating metapackages ``` -------------------------------- ### Mount and Use ISO with ImDisk Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/guides/create/mount-an-iso-in-chocolatey-package.mdx This PowerShell script demonstrates downloading an ISO, mounting it using ImDisk, installing a package from the mounted ISO, and then unmounting it. Suitable for internal use or when direct download is preferred. ```powershell # Internal use: # - Option 1: If the ISO is smaller than 1GB, embed the binary directly into the package for the most reliable use skip this # - Option 2: Store ISO on a file share and skip this # - Option 3: Download from internal sources, like a binary (raw) repository in Artifactory, Nexus, or ProGet. # Community repo: Download the ISO file from the internet if you don't have distribution rights or the file is larger than 250MB. Get-ChocolateyWebFile 'WindowsSDK2008' "$env:temp\winsdk2008.iso" 'http://download.microsoft.com/download/f/e/6/fe6eb291-e187-4b06-ad78-bb45d066c30f/6.0.6001.18000.367-KRMSDK_EN.iso' # Next, mount the ISO file, ready for using it's contents (NOTE: the last parameter here is the drive letter that will be assigned to the mounted ISO) imdisk -a -f "$env:temp\winsdk2008.iso" -m "w:" # Run commands against the mounted ISO, in this case, run the setup.exe Install-ChocolateyInstallPackage 'WindowsSDK2008' 'exe' '/q' 'w:\Setup.exe' # Unmount the ISO file when finished imdisk -d -m w: ``` -------------------------------- ### Example packages.config with version numbers Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/guides/create/exporting-packages.mdx Shows the XML structure when the --include-version-numbers argument is used. ```xml ``` -------------------------------- ### Uninstall Chocolatey Package Basic Example Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/create/functions/uninstall-chocolateypackage.mdx A basic example demonstrating the usage of Uninstall-ChocolateyPackage with placeholder values for package name, installer type, silent arguments, and file path. ```powershell Uninstall-ChocolateyPackage '__NAME__' 'EXE_OR_MSI' 'SILENT_ARGS' 'FilePath' ``` -------------------------------- ### Preview Production Site Source: https://github.com/chocolatey/docs/blob/master/README.md After building, use this command to start a local server to preview the production site. Note that changes to source files will not be reflected in this preview. ```powershell yarn preview ``` -------------------------------- ### Execute Local Client Setup Script Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/guides/organizations/organizational-deployment-guide/client-setup.mdx Run the downloaded ClientSetup.ps1 script locally on the client machine using provided parameters. This assumes the script has already been saved to the current directory. ```powershell .\ClientSetup.ps1 @ScriptArgs ``` -------------------------------- ### Install and Manage Chocolatey Windows Services Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/licensed-extension/release-notes.mdx Use these functions to install, start, stop, and uninstall Windows services managed by Chocolatey. Ensure the service executable path is correctly defined. ```powershell $toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" $serviceExe = Join-Path $toolsDir 'service\chocolatey-agent.exe' $packageArgs = @{ Name = 'chocolatey-agent' DisplayName = 'Chocolatey Agent' Description = 'Chocolatey Agent is a background service for Chocolatey.' StartupType = 'Automatic' ServiceExecutablePath = $serviceExe } #Username, Password, -DoNotStartService are also considered Install-ChocolateyWindowsService @packageArgs # The other three methods simply take the service name. Start-ChocolateyWindowsService -Name 'chocolatey-agent' Stop-ChocolateyWindowsService -Name 'chocolatey-agent' Uninstall-ChocolateyWindowsService -Name 'chocolatey-agent' ``` -------------------------------- ### Reusable Prompt Function for Installations Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/guides/usage/development-environment-setup.mdx This PowerShell function, `Install-NeededFor`, prompts the user interactively about installing a specified package. It includes a timeout and a default answer, making it suitable for automated or semi-automated installation scripts. This function is a common utility in Chocolatey setup scripts. ```powershell function Install-NeededFor { param( [string] $packageName = '' ,[bool] $defaultAnswer = $true ) if ($packageName -eq '') {return $false} $yes = '6' $no = '7' $msgBoxTimeout='-1' $defaultAnswerDisplay = 'Yes' $buttonType = 0x4; if (!$defaultAnswer) { $defaultAnswerDisplay = 'No'; $buttonType= 0x104;} $answer = $msgBoxTimeout try { $timeout = 10 $question = "Do you need to install $($packageName)? Defaults to `'$defaultAnswerDisplay`' after $timeout seconds" $msgBox = New-Object -ComObject WScript.Shell $answer = $msgBox.Popup($question, $timeout, "Install $packageName", $buttonType) } catch { } if ($answer -eq $yes -or ($answer -eq $msgBoxTimeout -and $defaultAnswer -eq $true)) { write-host "Installing $packageName" return $true } write-host "Not installing $packageName" return $false } ``` -------------------------------- ### Install-BinFile Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/create/functions/install-binfile.mdx Creates a shim (or batch redirect) for a file that is on the PATH. ```APIDOC ## Install-BinFile ### Description Creates a shim (or batch redirect) for a file that is on the PATH. This function is useful for adding executables or other files to the system's PATH, especially when they are not automatically discovered by Chocolatey. ### Syntax ```powershell Install-BinFile ` -Name ` -Path ` [-UseStart] ` [-Command ] ` [-IgnoredArguments ] [] ``` ### Parameters #### Path Parameters - **Name** (String) - Required - The name of the file to create a shim for. - **Path** (String) - Required - The full path to the file that needs to be shimmed. #### Query Parameters None #### Request Body None ### Request Example ```powershell Install-BinFile -Name "myApp" -Path "C:\Tools\MyApp\app.exe" ``` ### Response #### Success Response (200) This function does not return any output. #### Response Example None ``` -------------------------------- ### Download and Internalize CCM Packages Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/central-management/setup/index.mdx This script downloads and internalizes various Chocolatey packages required for CCM setup, including core Chocolatey components, .NET runtimes, and SQL Server Express. Ensure you update the repository URL, API key, and C4B license GUID to match your environment. This process is crucial for preparing your internal package repository before proceeding with CCM installation. ```powershell # To run this, you need Chocolatey for Business installed (chocolatey / chocolatey.extension). # Update the values and remove the < > $YourInternalRepositoryPushUrl = '' $YourInternalRepositoryApiKey = '' # You get this from the chocolatey.license.xml file: $YourBusinessLicenseGuid = '' if(!(Test-Path C:\packages)){ $null = New-Item C:\packages -ItemType Directory } # Download Chocolatey community related items, no internalization necessary choco download chocolatey chocolateygui --force --source="'https://community.chocolatey.org/api/v2/'" --output-directory="'C:\packages'" # This is for other Community Related Items choco download dotnet4.5.2 dotnetfx --force --internalize --internalize-all-urls --append-use-original-location --source="'https://community.chocolatey.org/api/v2/'" --output-directory="'C:\packages'" # This is for SQL Server Express # Not necessary if you already have SQL Server @('sql-server-express','sql-server-management-studio') | Foreach-Object { choco download $_ --force --internalize --internalize-all-urls --append-use-original-location --source="'https://community.chocolatey.org/api/v2/'" --output-directory="'C:\packages'" } # We must use the 8.x.x versions of these packages, so we need to download/internalize these specific items. At the time of publishing, the most recent version of this package is 8.0.8, but later package versions (within the 8.x.x release) are expected to work. @('dotnet-8.0-runtime', 'dotnet-8.0-aspnetruntime') | Foreach-Object { choco download $_ --version 8.0.8 --force --internalize --internalize-all-urls --append-use-original-location --source="'https://community.chocolatey.org/api/v2/'" --output-directory="'C:\packages'" } ``` -------------------------------- ### Install-ChocolateyZipPackage Examples Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/create/functions/install-chocolateyzippackage.mdx Common usage patterns for downloading and extracting ZIP packages. ```powershell Install-ChocolateyZipPackage -PackageName 'gittfs' -Url 'https://github.com/downloads/spraints/git-tfs/GitTfs-0.11.0.zip' -UnzipLocation $gittfsPath ``` ```powershell Install-ChocolateyZipPackage -PackageName 'sysinternals' ` -Url 'http://download.sysinternals.com/Files/SysinternalsSuite.zip' ` -UnzipLocation "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)" ``` ```powershell Install-ChocolateyZipPackage -PackageName 'sysinternals' ` -Url 'http://download.sysinternals.com/Files/SysinternalsSuite.zip' ` -UnzipLocation "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)" ` -Url64 'http://download.sysinternals.com/Files/SysinternalsSuitex64.zip' ``` -------------------------------- ### Install Package via PowerShell Source: https://github.com/chocolatey/docs/blob/master/src/content/docs/en-us/create/create-packages.mdx Example of a modern chocolateyInstall.ps1 script using the Install-ChocolateyPackage helper. ```powershell $packageName = 'windirstat' $fileType = 'exe' $url = 'http://prdownloads.sourceforge.net/windirstat/windirstat1_1_2_setup.exe' $silentArgs = '/S' Install-ChocolateyPackage $packageName $fileType $silentArgs $url ```