### Install Chocolatey Central Management Quickstart Source: https://github.com/chocolatey/choco/wiki/ChocolateyForBusinessQuickStartGuide Installs the quickstart package from a local source, requiring the full path to the license file provided via email. ```powershell choco install chocolatey-c4b-quickstart --source . -y --params "'/LicenseFile:'" ``` -------------------------------- ### Install Chocolatey Package Example Source: https://github.com/chocolatey/choco/wiki/CreatePackages Example of how to use the Install-ChocolateyPackage function to install a package. Ensure the URL points to a valid installer and silent arguments are correctly specified. ```powershell $packageName = 'windirstat' $fileType = 'exe' $url = 'http://prdownloads.sourceforge.net/windirstat/windirstat1_1_2_setup.exe' $silentArgs = '/S' Install-ChocolateyPackage $packageName $fileType $silentArgs $url ``` -------------------------------- ### Install Packages via Puppet Source: https://github.com/chocolatey/choco/wiki/Installation Examples of installing various 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://chocolatey.org/api/v2/', } package {'screentogif': ensure => '2.2.160907', source => 'https://chocolatey.org/api/v2/', } package {'dotnet4.5.2': ensure => latest, } ``` -------------------------------- ### Install Override - Example Command Source: https://github.com/chocolatey/choco/wiki/FeaturesInstallDirectoryOverride This example demonstrates how Chocolatey for Business automatically determines the correct installer arguments to override the installation directory. The package must use Chocolatey install helpers and be installing software with a native installer. ```powershell choco install 1password -s . -y --dir c:\1password ``` -------------------------------- ### Execute ClientSetup.ps1 Source: https://github.com/chocolatey/choco/wiki/QuickDeployment/V2/QuickDeploymentClientSetup Downloads and runs the primary setup script to install Chocolatey, configure sources, and set up the agent service. ```powershell $downloader = New-Object -TypeName System.Net.WebClient Invoke-Expression ($downloader.DownloadString('https://chocoserver:8443/repository/choco-install/ClientSetup.ps1')) ``` -------------------------------- ### Install Package with Parameters Source: https://github.com/chocolatey/choco/wiki/How-To-Parse-PackageParameters-Argument Example command for installing a Chocolatey package with custom parameters. Note the use of single quotes around the parameters for proper shell interpretation. ```sh choco install --params "'/key:value key2:value'" ``` -------------------------------- ### Basic EXE Installation Source: https://github.com/chocolatey/choco/wiki/HelpersInstallChocolateyInstallPackage Performs a basic installation of an EXE file with minimal arguments. This is a shorthand syntax for common installations. ```powershell Install-ChocolateyInstallPackage 'bob' 'exe' '/S' "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)\bob.exe" ``` -------------------------------- ### Automated Setup Script Source: https://github.com/chocolatey/choco/wiki/How-To-Setup-Offline-Installation A comprehensive script for setting up directories, installing Chocolatey, and applying licenses in offline environments. ```powershell # Ensure we can run everything Set-ExecutionPolicy Bypass -Scope Process -Force # Setting up directories for values New-Item -Path "$env:SystemDrive\choco-setup" -ItemType Directory -Force New-Item -Path "$env:SystemDrive\choco-setup\files" -ItemType Directory -Force New-Item -Path "$env:SystemDrive\choco-setup\packages" -ItemType Directory -Force # Install Chocolatey # NONADMIN - you'll need this uncommented to redirect to a different location: # $env:ChocolateyInstall="$env:ProgramData\chocoportable" iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) # Are you military, government, or for some other reason have FIPS compliance turned on? #choco feature enable --name="'useFipsCompliantChecksums'" # Add license to setup and to local install New-Item $env:ChocolateyInstall\license -ItemType Directory -Force Write-Host "Please add chocolatey.license.xml to '$env:SystemDrive\choco-setup\files'." Write-Host 'Once you do so, press any key to continue...'; $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); Copy-Item $env:SystemDrive\choco-setup\files\chocolatey.license.xml $env:ChocolateyInstall\license\chocolatey.license.xml -Force # Install Chocolatey Licensed Extension choco upgrade chocolatey.extension -y --pre Write-Host "If you see what looks like an error about a missing extension, that is what this step does so it will clear up on next command." # C4BTRIAL: Place nupkgs into the "$env:SystemDrive\choco-setup\packages" directory (add a script here to do so) ``` -------------------------------- ### Install package with parameters and installer arguments Source: https://github.com/chocolatey/choco/wiki/CommandsInstall Provides both package parameters and direct installer arguments. Install arguments are appended to the silent arguments defined in the package. ```powershell choco install git -y --params="'/GitAndUnixToolsOnPath /NoAutoCrlf'" --install-args="'/DIR=C:\\git'" ``` -------------------------------- ### Automate Chocolatey.Server Setup with PowerShell Source: https://github.com/chocolatey/choco/wiki/How-To-Set-Up-Chocolatey-Server A comprehensive script to install prerequisites, configure IIS, and set up the application pool for Chocolatey.Server. ```powershell $siteName = 'ChocolateyServer' $appPoolName = 'ChocolateyServerAppPool' $sitePath = 'c:\tools\chocolatey.server' function Add-Acl { [CmdletBinding()] Param ( [string]$Path, [System.Security.AccessControl.FileSystemAccessRule]$AceObject ) Write-Verbose "Retrieving existing ACL from $Path" $objACL = Get-ACL -Path $Path $objACL.AddAccessRule($AceObject) Write-Verbose "Setting ACL on $Path" Set-ACL -Path $Path -AclObject $objACL } function New-AclObject { [CmdletBinding()] Param ( [string]$SamAccountName, [System.Security.AccessControl.FileSystemRights]$Permission, [System.Security.AccessControl.AccessControlType]$AccessControl = 'Allow', [System.Security.AccessControl.InheritanceFlags]$Inheritance = 'None', [System.Security.AccessControl.PropagationFlags]$Propagation = 'None' ) New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule($SamAccountName, $Permission, $Inheritance, $Propagation, $AccessControl) } if ($null -eq (Get-Command -Name 'choco.exe' -ErrorAction SilentlyContinue)) { Write-Warning "Chocolatey not installed. Cannot install standard packages." Exit 1 } # Install Chocolatey.Server prereqs choco install IIS-WebServer --source windowsfeatures choco install IIS-ASPNET45 --source windowsfeatures # Install Chocolatey.Server choco upgrade chocolatey.server -y # Step by step instructions here https://chocolatey.org/docs/how-to-set-up-chocolatey-server#setup-normally # Import the right modules Import-Module WebAdministration # Disable or remove the Default website Get-Website -Name 'Default Web Site' | Stop-Website Set-ItemProperty "IIS:\Sites\Default Web Site" serverAutoStart False # disables website # Set up an app pool for Chocolatey.Server. Ensure 32-bit is enabled and the managed runtime version is v4.0 (or some version of 4). Ensure it is "Integrated" and not "Classic". New-WebAppPool -Name $appPoolName -Force Set-ItemProperty IIS:\AppPools\$appPoolName enable32BitAppOnWin64 True # Ensure 32-bit is enabled Set-ItemProperty IIS:\AppPools\$appPoolName managedRuntimeVersion v4.0 # managed runtime version is v4.0 Set-ItemProperty IIS:\AppPools\$appPoolName managedPipelineMode Integrated # Ensure it is "Integrated" and not "Classic" Restart-WebAppPool -Name $appPoolName # likely not needed ... but just in case ``` -------------------------------- ### Configure ClientSetup.ps1 Parameters Source: https://github.com/chocolatey/choco/wiki/QuickDeployment/QuickDeploymentInternetSetup This example shows how to set the necessary parameters for the ClientSetup.ps1 script before running it on an endpoint. Ensure you replace the placeholder values with your actual configuration, including unique salt additives and the correct FQDN. ```powershell # CHANGE THESE VALUES! $clientCommunicationSalt = '2iLYko*f9y9kiv!Aw7kpZhBz7RnWQVHg' # example 32 character password. MUST BE UNIQUE $serverCommunicationSalt = 'QQmgDxagB@nBR*.UyHx!-qrw4kWvwrT!' # example 32 character password. MUST BE UNIQUE $fqdn = 'chocoserver' # If you have adjusted your FQDN, you HAVE to CHANGE this to reflect that $password = 'x3mrj3NbGtkZBzJatLe9AcUtT8G_Y4Ra' # example 32 character password ``` -------------------------------- ### Example of Silent Arguments for Executable Installers Source: https://github.com/chocolatey/choco/wiki/HelpersInstallChocolateyInstallPackage When using executable installers, SilentArgs are appended to the file path. This example shows how to pass '/S' as a silent argument. ```powershell "c:\path\setup.exe" /S ``` -------------------------------- ### Download Examples Source: https://github.com/chocolatey/choco/wiki/CommandsDownload Common examples for downloading packages, including internalization options for business users. ```bash choco download sysinternals ``` ```bash choco download notepadplusplus --internalize ``` ```bash choco download notepadplusplus.install --internalize --resources-location \\server\share ``` ```bash choco download notepadplusplus.install --internalize --resources-location http://somewhere/internal --append-useoriginallocation ``` ```bash choco download KB3033929 --internalize -internalize-all-urls --append-useoriginallocation ``` ```bash choco download firefox --internalize locale=es-AR ``` -------------------------------- ### Install WebPI Package from Alternative Source Source: https://github.com/chocolatey/choco/wiki/ChocolateyVsNinite Demonstrates installing a WebPI package from an alternative source. ```bash choco install IISExpress --source webpi ``` -------------------------------- ### Install Package from Alternative Source Source: https://github.com/chocolatey/choco/wiki/ChocolateyVsNinite Demonstrates installing a package from an alternative source like Cygwin. ```bash choco install bash --source cygwin ``` -------------------------------- ### Configure Local Install Path Source: https://github.com/chocolatey/choco/wiki/How-To-Setup-Offline-Installation Example of modifying the local package path in the installation script. ```powershell $localChocolateyPackageFilePath = 'c:\packages\chocolatey.0.10.0.nupkg' ``` ```powershell $localChocolateyPackageFilePath = 'c:\choco-setup\packages\chocolatey.0.10.8.nupkg' ``` -------------------------------- ### Install Ruby Gem from Alternative Source Source: https://github.com/chocolatey/choco/wiki/ChocolateyVsNinite Demonstrates installing a Ruby Gem from an alternative source. ```bash choco isntall gemcutter --source ruby ``` -------------------------------- ### Install Nexus Repository Package Source: https://github.com/chocolatey/choco/wiki/ChocolateyForBusinessQuickStartGuide Installs the nexus-repository package. This step is optional if Nexus is already installed. For a clean setup, consider uninstalling and reinstalling. ```powershell choco install nexus-repository -y --no-progress ``` -------------------------------- ### Running Set-QDEnvironment.ps1 with Custom Certificate Source: https://github.com/chocolatey/choco/wiki/QuickDeployment/V2/QuickDeploymentDesktopReadme This section covers the setup using a custom certificate (domain or pre-existing). The certificate must be present in either the `Cert:\LocalMachine\My` or `Cert:\LocalMachine\TrustedPeople` stores, and its private key must be exportable. You can use either the certificate's thumbprint or its subject. ```APIDOC ## Run Set-QDEnvironment.ps1 with Custom Certificate ### Description Executes the `Set-QDEnvironment.ps1` script using a custom certificate. The certificate must be in the local machine's certificate store, and its private key must be exportable. ### Prerequisites - Custom certificate (domain or pre-existing) installed in `Cert:\LocalMachine\My` or `Cert:\LocalMachine\TrustedPeople`. - The private key of the certificate must be exportable. - PowerShell must be opened as Administrator. ### Commands #### Using Certificate Thumbprint ```powershell & C:\choco-setup\files\Set-QDEnvironment.ps1 -NexusApiKey "{{NugetApiKey}}" -CertificateThumbprint "INSERT_CERTIFICATE_THUMBPRINT_HERE" -CertificateDnsName "INSERT_DNS_NAME_HERE" ``` #### Using Certificate Subject ```powershell & C:\choco-setup\files\Set-QDEnvironment.ps1 -NexusApiKey "{{NugetApiKey}}" -CertificateSubject "INSERT_CERTIFICATE_SUBJECT_HERE" -CertificateDnsName "INSERT_DNS_NAME_HERE" ``` ### Parameters #### Request Body - **-NexusApiKey** (string) - Required - The api key for your nexus installation. - **-CertificateThumbprint** (string) - Optional - The thumbprint of the custom certificate. - **-CertificateSubject** (string) - Optional - The subject name of the custom certificate (e.g., `your.domain.com`). Do not include the 'CN=' prefix. - **-CertificateDnsName** (string) - Optional - Required if using a wildcard certificate or if the subject does not contain wildcards and you are providing `-CertificateThumbprint` or `-CertificateSubject`. Used for internet-facing configurations. - **-InternetEnabled** (switch) - Optional - Enables internet-facing client configuration and additional security features. Use with caution and secure generated passwords/salts. ``` -------------------------------- ### Run Set-QDEnvironment.ps1 with Custom Certificate Source: https://github.com/chocolatey/choco/wiki/QuickDeployment/V2/QuickDeploymentDesktopReadme Executes the setup script using an existing certificate from the local machine store. The certificate's private key must be exportable. ```powershell # If you have the thumbprint, run: & C:\choco-setup\files\Set-QDEnvironment.ps1 -NexusApiKey "{{NugetApiKey}}" -CertificateThumbprint "INSERT_CERTIFICATE_THUMBPRINT_HERE" -CertificateDnsName "INSERT_DNS_NAME_HERE" # If you have the subject instead, run: & C:\choco-setup\files\Set-QDEnvironment.ps1 -NexusApiKey "{{NugetApiKey}}" -CertificateSubject "INSERT_CERTIFICATE_SUBJECT_HERE" -CertificateDnsName "INSERT_DNS_NAME_HERE" ``` -------------------------------- ### Install a package with Chocolatey Source: https://github.com/chocolatey/choco/wiki/ChocolateyVsNinite Example of a PowerShell function call to install software using specific parameters and checksum validation. ```powershell Install-ChocolateyPackage 'windirstat' 'exe' '/S' 'https://windirstat.info/wds_current_setup.exe' -Checksum 123456 -ChecksumType 'sha256' ``` -------------------------------- ### Install Chocolatey Central Management with domain credentials Source: https://github.com/chocolatey/choco/wiki/CentralManagement/CentralManagementSetupService Examples for passing domain account credentials during installation or upgrade of the management service. ```powershell choco install chocolatey-management-service -y --params="'/Username:domain\account /EnterPassword'" ``` ```powershell choco install chocolatey-management-service -y --params="'/Username:'" --package-parameters-sensitive="'/Password:'" ``` -------------------------------- ### Get-CCMComputer Usage Examples Source: https://github.com/chocolatey/choco/wiki/CentralManagement/ChocoCCM/Functions/GetCCMComputer Practical examples for querying computer information by default, by name, or by ID. ```powershell Get-CCMComputer ``` ```powershell Get-CCMComputer -Computer web1 ``` ```powershell Get-CCMComputer -Id 13 ``` -------------------------------- ### Install Chocolatey Nexus Setup Package Source: https://github.com/chocolatey/choco/wiki/ChocolateyForBusinessQuickStartGuide Installs the chocolatey-nexus-setup package from a local source. This package configures Nexus with necessary repositories and scripts. ```powershell choco install chocolatey-nexus-setup --source="'C:\choco-setup\packages'" ``` -------------------------------- ### Install-ChocolateyZipPackage Examples Source: https://github.com/chocolatey/choco/wiki/HelpersInstallChocolateyZipPackage Common usage patterns for downloading and unzipping packages, including handling 64-bit specific URLs. ```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 Portable Packages Source: https://github.com/chocolatey/choco/wiki/Installation Examples of installing portable package types without requiring administrative rights. These packages are designed for non-admin users. ```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://chocolatey.org/packages?q=id%3Aportable ``` -------------------------------- ### Install Python Package from Alternative Source Source: https://github.com/chocolatey/choco/wiki/ChocolateyVsNinite Demonstrates installing a Python package from an alternative source. ```bash choco install sphynx --source python ``` -------------------------------- ### Run Set-QDEnvironment.ps1 with Default Certificate Source: https://github.com/chocolatey/choco/wiki/QuickDeployment/V2/QuickDeploymentDesktopReadme Executes the setup script using a newly-generated self-signed certificate. Must be run from an Administrator PowerShell window, not the PowerShell ISE. ```powershell & C:\choco-setup\files\Set-QDEnvironment.ps1 -NexusApiKey "{{NugetApiKey}}" ``` -------------------------------- ### Install Chocolatey.Server using PowerShell Source: https://github.com/chocolatey/choco/wiki/How-To-Setup-Offline-Installation This script ensures the execution policy allows script execution and then installs or upgrades Chocolatey.Server. It directs users to external documentation for further setup steps. ```powershell # Ensure we can run everything Set-ExecutionPolicy Bypass -Scope Process -Force # Install Chocolatey.Server choco upgrade chocolatey.server -y --pre Write-Warning "Follow the steps at https://chocolatey.org/docs/how-to-set-up-chocolatey-server#setup-normally and https://chocolatey.org/docs/how-to-set-up-chocolatey-server#additional-configuration for now." # more may be added later ``` -------------------------------- ### Upgrade Command Examples Source: https://github.com/chocolatey/choco/wiki/CommandsUpgrade Common usage patterns for upgrading packages, including handling multiple packages, parameters, and sources. ```shell choco upgrade chocolatey choco upgrade notepadplusplus googlechrome atom 7zip choco upgrade notepadplusplus googlechrome atom 7zip -dvfy choco upgrade git -y --params="'/GitAndUnixToolsOnPath /NoAutoCrlf'" choco upgrade git -y --params="'/GitAndUnixToolsOnPath /NoAutoCrlf'" --install-args="'/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 upgrade nodejs.install --version 0.10.35 choco upgrade git -s "'https://somewhere/out/there'" choco upgrade git -s "'https://somewhere/protected'" -u user -p pass choco upgrade all choco upgrade all --except="'skype,conemu'" ``` -------------------------------- ### Install-ChocolateyPath Usage Source: https://github.com/chocolatey/choco/wiki/Troubleshooting Example of the command used to update the system PATH during package installation. ```powershell Install-ChocolateyPath $binPath ``` -------------------------------- ### Get CCM Group Information Source: https://github.com/chocolatey/choco/wiki/CentralManagement/ChocoCCM/Functions/GetCCMGroup Retrieves all group information for your CCM installation. No specific parameters are required. ```powershell Get-CCMGroup ``` -------------------------------- ### Get Help for Azure VM Deployment Script Source: https://github.com/chocolatey/choco/wiki/QuickDeployment/V2/QuickDeploymentSetup Displays full parameter documentation for the New-QDEAzureVM.ps1 script. ```powershell Get-Help New-QDEAzureVM.ps1 -full ``` -------------------------------- ### Custom Chocolatey Install Script Template Source: https://github.com/chocolatey/choco/wiki/How-To-Create-Custom-Package-Templates An example of a `chocolateyInstall.ps1` script for a custom Chocolatey package template. It shows how to use templated values and configure package installation arguments, including MSI specific options. ```powershell # Custom value: [[CustomValue]] $ErrorActionPreference = 'Stop'; # stop on all errors [[AutomaticPackageNotesInstaller]] $packageName = '[[PackageName]]' $toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" $fileLocation = Join-Path $toolsDir 'NAME_OF_EMBEDDED_INSTALLER_FILE' $packageArgs = @{ packageName = $packageName file = $fileLocation fileType = '[[InstallerType]]' #only one of these: exe, msi, msu #MSI silentArgs = "/qn /norestart /l*v `"$env:TEMP\chocolatey\$($packageName)\$($packageName).MsiInstall.log`"" validExitCodes= @(0, 3010, 1641) #OTHERS #silentArgs ='[[SilentArgs]]' # /s /S /q /Q /quiet /silent /SILENT /VERYSILENT -s - try any of these to get the silent installer #validExitCodes= @(0) #please insert other valid exit codes here } Install-ChocolateyInstallPackage @packageArgs ``` -------------------------------- ### Debug Installation with Verbose and No Operation Flags Source: https://github.com/chocolatey/choco/wiki/Troubleshooting Use the `-dv --noop` flags with Chocolatey commands to get detailed output and simulate the installation process without making changes. This is useful for diagnosing source and dependency issues. ```powershell choco install -dv --noop ``` -------------------------------- ### Install-BinFile Source: https://github.com/chocolatey/choco/wiki/HelpersInstallBinFile Creates a shim for a file to add it to the system PATH. ```APIDOC ## Install-BinFile ### Description Creates a shim (or batch redirect) for a file that is on the PATH. This function is used to explicitly shim files that are not automatically discovered by Chocolatey. ### Parameters #### Path Parameters - **Name** (String) - Required - The name of the redirect file, will have .exe appended to it. - **Path** (String) - Required - The path to the original file. Can be relative from $env:ChocolateyInstall\bin back to your file or a full path to the file. #### Optional Parameters - **UseStart** (Switch) - Optional - Should be passed if the shim should not wait on the action to complete (typically for GUI apps). - **Command** (String) - Optional - Additional command arguments to be passed every time to the command. - **IgnoredArguments** (Object[]) - Optional - Allows splatting with arguments that do not apply. ``` -------------------------------- ### Download a file with multiple URL options Source: https://github.com/chocolatey/choco/wiki/HelpersGetChocolateyWebFile This example shows how to specify both a 32-bit URL and a 64-bit URL for downloading a file. The function will automatically select the appropriate URL based on the system architecture, unless the `--forceX86` parameter is used. ```powershell Get-ChocolateyWebFile '__NAME__' 'C:\somepath\somename.exe' 'URL' '64BIT_URL_DELETE_IF_NO_64BIT' ``` -------------------------------- ### Getting Installer File Path within a Package Source: https://github.com/chocolatey/choco/wiki/HelpersInstallChocolateyInstallPackage This snippet demonstrates how to construct the full path to an installer file when embedding it within a Chocolatey package. It uses PowerShell's Split-Path and MyInvocation to determine the script's directory. ```powershell "$(Split-Path -parent $MyInvocation.MyCommand.Definition)\INSTALLER_FILE" ``` -------------------------------- ### Parameter Example for packageFolder Source: https://github.com/chocolatey/choco/wiki/HelpersGetChocolateyBins Shows the expected format for the packageFolder parameter. ```powershell 'c:\program files (x86)\vim\vim73\' ``` -------------------------------- ### Download Chocolatey Agent Package Source: https://github.com/chocolatey/choco/wiki/Installation-Licensed Download the Chocolatey Agent package, which is required for managing Chocolatey installations in an offline setup. ```bash choco download chocolatey-agent --source https://licensedpackages.chocolatey.org/api/v2/ --ignore-dependencies ``` -------------------------------- ### Install-ChocolateyShortcut Parameters Source: https://github.com/chocolatey/choco/wiki/HelpersInstallChocolateyShortcut Detailed parameter documentation for the Install-ChocolateyShortcut cmdlet. ```APIDOC ## Install-ChocolateyShortcut ### Description Creates a shortcut with various configuration options such as window style, administrative privileges, and taskbar pinning. ### Parameters #### -WindowStyle () - **Required**: No - **Default**: 0 - **Description**: Type of window the target application should open with. 0 = Hidden, 1 = Normal Size, 3 = Maximized, 7 = Minimized. #### -RunAsAdmin - **Required**: No - **Default**: False - **Description**: Set "Run As Administrator" checkbox for the created shortcut. #### -PinToTaskbar - **Required**: No - **Default**: False - **Description**: Pin the new shortcut to the taskbar. #### -IgnoredArguments () - **Required**: No - **Description**: Allows splatting with arguments that do not apply. Do not use directly. ### Common Parameters This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. ``` -------------------------------- ### Install-ChocolateyPackage - With Options Source: https://github.com/chocolatey/choco/wiki/HelpersInstallChocolateyPackage Demonstrates how to pass additional options, such as custom headers, to the package installation process. ```APIDOC ## POST /api/packages/install ### Description Installs a package with custom options, including headers. ### Method POST ### Endpoint /api/packages/install ### Parameters #### Request Body - **packageName** (string) - Required - The name of the package. - **fileType** (string) - Required - The type of the installer file (e.g., 'exe'). - **silentArgs** (string) - Required - Arguments to use for silent installation. - **url** (string) - Required - The URL for the installer. - **options** (object) - Optional - An object containing additional options, such as headers. - **Headers** (object) - Optional - Key-value pairs for request headers. ### Request Example ```json { "packageName": "package", "fileType": "exe", "silentArgs": "/S", "url": "https://somelocation.com/thefile.exe", "options": { "Headers": { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.3", "Accept-Language": "en-GB,en-US;q=0.8,en;q=0.6", "Cookie": "requiredinfo=info", "Referer": "https://somelocation.com/" } } } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message of the installation. #### Response Example ```json { "message": "Package 'package' installed successfully with custom options." } ``` ``` -------------------------------- ### Automate Chocolatey Client Setup Source: https://github.com/chocolatey/choco/wiki/QuickDeployment/QuickDeploymentInternetSetup This PowerShell script installs Chocolatey, configures internal repositories, and sets up the communication channel for CCM. ```powershell # Touch NOTHING below this line $user = 'chocouser' $securePassword = $password | ConvertTo-SecureString -AsPlainText -Force $repositoryUrl = "https://$($fqdn):8443/repository/ChocolateyInternal/" $credential = [pscredential]::new($user, $securePassword) $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 = $serverCommunicationSalt InternetEnabled = $true RepositoryUrl = $repositoryUrl } & ([scriptblock]::Create($script)) @params ``` -------------------------------- ### Install Service with AttachDBFile (Unsupported) Source: https://github.com/chocolatey/choco/wiki/CentralManagement/CentralManagementSetupService This command demonstrates an unsupported configuration using AttachDBFile or User Instance. It is strongly recommended to avoid this approach. ```powershell choco install chocolatey-management-service -y --package-parameters="'/ConnectionString:Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|SomeDbFile.mdf;User Instance=true;'" ``` -------------------------------- ### Identify TLS Connection Errors Source: https://github.com/chocolatey/choco/wiki/Installation Example error messages encountered when the installation environment lacks the required TLS 1.2 support. ```sh Exception calling "DownloadString" with "1" argument(s): "The underlying connection was closed: An unexpected error occurred on a receive." At line:1 char:1 + iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/in ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException ``` ```sh Exception calling "DownloadString" with "1" argument(s): "The request was aborted: Could not create SSL/TLS secure channel." At line:1 char:51 + ... ess -Force; iex ((New-Object System.Net.WebClient).DownloadString('ht ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException ``` -------------------------------- ### Get Machine Environment Variable Source: https://github.com/chocolatey/choco/wiki/HelpersGetEnvironmentVariable Retrieves the 'PATH' environment variable for the machine scope. This example does not use -PreserveVariables, so the variable will be expanded. ```powershell Get-EnvironmentVariable -Name 'PATH' -Scope Machine ``` -------------------------------- ### Set up IIS Website and Permissions Source: https://github.com/chocolatey/choco/wiki/How-To-Set-Up-Chocolatey-Server Configures an IIS website and applies necessary file system permissions for the application pool. ```powershell # Set up an IIS website pointed to the install location and set it to use the app pool. New-Website -Name $siteName -ApplicationPool $appPoolName -PhysicalPath $sitePath # Add permissions to c:\tools\chocolatey.server: 'IIS_IUSRS', 'IUSR', "IIS APPPOOL\$appPoolName" | ForEach-Object { $obj = New-AclObject -SamAccountName $_ -Permission 'ReadAndExecute' -Inheritance 'ContainerInherit','ObjectInherit' Add-Acl -Path $sitePath -AceObject $obj } # Add the permissions to the App_Data subfolder: $appdataPath = Join-Path -Path $sitePath -ChildPath 'App_Data' 'IIS_IUSRS', "IIS APPPOOL\$appPoolName" | ForEach-Object { $obj = New-AclObject -SamAccountName $_ -Permission 'Modify' -Inheritance 'ContainerInherit', 'ObjectInherit' Add-Acl -Path $appdataPath -AceObject $obj } ``` -------------------------------- ### Automated Chocolatey Client Setup Script Source: https://github.com/chocolatey/choco/wiki/How-To-Setup-Offline-Installation A PowerShell script to automate the initial installation and environment configuration for Chocolatey clients using an internal server. ```powershell # This is a base url and should not include the "/chocolatey" (for Chocolatey.Server) or any url path to a NuGet/Chocolatey Packages API $baseUrl = "http://localhost" # this is the sub path, it will combine the above with this in the script $baseUrl/$repositoryUrlPath $repositoryUrlPath = "chocolatey" # Ensure we can run everything Set-ExecutionPolicy Bypass -Scope Process -Force; # Reroute TEMP to a local location New-Item $env:ALLUSERSPROFILE\choco-cache -ItemType Directory -Force $env:TEMP = "$env:ALLUSERSPROFILE\choco-cache" # Ignore proxies since we are using internal locations $env:chocolateyIgnoreProxy = 'true' # Set proxy settings if necessary #$env:chocolateyProxyLocation = 'https://local/proxy/server' #$env:chocolateyProxyUser = 'username' #$env:chocolateyProxyPassword = 'password' # Install Chocolatey # This is for use with Chocolatey.Server only: iex ((New-Object System.Net.WebClient).DownloadString("$baseUrl/install.ps1")) # You'll need to also use the script you used for local installs to get Chocolatey installed. ``` -------------------------------- ### Package Creation with Options Source: https://github.com/chocolatey/choco/wiki/CommandsNew Generate a new package with specified version, maintainer name, and installer URL. Ensure proper quoting for arguments with spaces. ```bash choco new bob -a --version 1.2.0 maintainername="'This guy'" ``` ```bash choco new bob silentargs="'/S'" url="'https://somewhere/out/there.msi'" ``` -------------------------------- ### Full Chocolatey Offline Setup Script Source: https://github.com/chocolatey/choco/wiki/How-To-Setup-Offline-Installation A comprehensive PowerShell script for setting up Chocolatey on an offline machine. It includes installation, source management, license application, and feature enablement. ```powershell # Ensure we can run everything Set-ExecutionPolicy Bypass -Scope Process -Force # Install Chocolatey & $env:SystemDrive\choco-setup\files\ChocolateyLocalInstall.ps1 # Are you military, government, or for some other reason have FIPS compliance turned on? # choco feature enable --name="'useFipsCompliantChecksums'" # Sources - Remove community repository and add a local folder source choco source remove --name="'chocolatey'" choco source add --name="'local'" --source="'$env:SystemDrive\choco-setup\packages'" # Add license to setup and to local install New-Item "$env:ChocolateyInstall\license" -ItemType Directory -Force Copy-Item -Path "$env:SystemDrive\choco-setup\files\chocolatey.license.xml" -Destination "$env:ChocolateyInstall\license\chocolatey.license.xml" -Force # Sources - Disable licensed source choco source disable --name="'chocolatey.licensed'" Write-Host "You can ignore the red text in the output above, as it is more of a warning until we have chocolatey.extension installed" # Install Chocolatey Licensed Extension choco upgrade chocolatey.extension -y --pre ``` -------------------------------- ### Install a Windows Service with Parameters Source: https://github.com/chocolatey/choco/wiki/HelpersInstallChocolateyWindowsService Installs a Windows Service using a hashtable for parameters. This method is useful for organizing multiple arguments. ```powershell $toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" $serviceExe = Join-Path $toolsDir 'service\dan-agent.exe' $packageArgs = @{ Name = 'dan' DisplayName = 'Dan Agent' ServiceExecutablePath = $serviceExe Username = 'DanTheBuilder' } Install-ChocolateyWindowsService @packageArgs ``` -------------------------------- ### Parse Package Parameters in ChocolateyInstall Source: https://github.com/chocolatey/choco/wiki/How-To-Parse-PackageParameters-Argument Use `Get-PackageParameters` to parse parameters passed to your Chocolatey package. This example shows how to set default values and construct silent arguments for installation. ```powershell $pp = Get-PackageParameters if (!$pp['Port']) { $pp['Port'] = '81' } if (!$pp['Edition']) { $pp['Edition'] = 'LicenseKey' } # you can also use the values like this: if (!$pp.InstallationPath) { $pp.InstallationPath = "$env:SystemDrive\temp" } $silentArgs = "/S /Port:$($pp['Port']) /Edition:$($pp['Edition']) /InstallationPath:$($pp['InstallationPath'])" if ($pp['AdditionalTools'] -eq 'true') { $silentArgs += " /Additionaltools" } Write-Debug "This would be the Chocolatey Silent Arguments: $silentArgs" ``` -------------------------------- ### View help for package generation Source: https://github.com/chocolatey/choco/wiki/CreatePackages Display available options for creating new packages. ```bash choco new -h ```