### Chocolatey Package Installation Examples (Command Line) Source: https://docs.chocolatey.org/en-us/choco/setup These are example commands demonstrating how to install various portable packages using Chocolatey. The examples include installing agent software, development tools, and text editors. Some packages are commented out, indicating they might not be available or are optional. ```bash 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 ``` -------------------------------- ### Chef Example: Bootstrapping and Package Installation Source: https://docs.chocolatey.org/en-us/features/integrations An in-depth Chef example demonstrating how to include the Chocolatey cookbook and manage package installations, including directory setup and iterating through packages. ```ruby include_recipe 'chocolatey' home = Dir.home %W( #{home}/.chef #{home}/chef #{home}/chef/cookbooks ).each do |directory| directory directory end packages = node['chefdk_bootstrap']['package'] packages.each do |pkg, install| include_recipe "#{cookbook_name}::#{pkg}" if install end ``` -------------------------------- ### Manage Chocolatey Windows Services with PowerShell Source: https://docs.chocolatey.org/en-us/licensed-extension/release-notes Demonstrates how to manage Chocolatey Windows Services using PowerShell cmdlets. This includes installing, starting, stopping, and uninstalling services. The examples utilize package arguments for installation and service names for other operations. ```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' ``` -------------------------------- ### Install Chocolatey Package Example (PowerShell) Source: https://docs.chocolatey.org/en-us/create/create-packages This PowerShell script demonstrates how to use the `Install-ChocolateyPackage` function to install a software package. It specifies the package name, file type, silent installation arguments, and the URL for the installer. Ensure Chocolatey is installed and the execution policy allows scripts to run. ```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 Chocolatey GUI Globally with Parameters Source: https://docs.chocolatey.org/en-us/chocolatey-gui/setup/installation This example shows how to install Chocolatey GUI and apply the specified parameters globally for all users on the machine. The '/Global' parameter is added to the list of configuration options. ```bash choco install chocolateygui --params="'/ShowConsoleOutput=$true /UseDelayedSearch=$false /OutdatedPackagesCacheDurationInMinutes=120 /Global'" ``` -------------------------------- ### Chocolatey Offline Setup Script (PowerShell) Source: https://docs.chocolatey.org/en-us/guides/organizations/organizational-deployment-guide This PowerShell script automates the setup of Chocolatey for offline installations. It creates directories, installs Chocolatey, handles license files, and internalizes required packages and extensions. Dependencies include PowerShell and the ability to download initial Chocolatey install script. ```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://community.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:ChocoInstall\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:ChocoInstall\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 the next command." # Set Configuration choco config set --name cacheLocation --value $env:ChocoInstall\choco-cache choco config set --name commandExecutionTimeoutSeconds --value 14400 #TODO: Add other items you would configure here # https://docs.chocolatey.org/en-us/configuration # Set Licensed Configuration choco feature enable --name="'internalizeAppendUseOriginalLocation'" choco feature enable --name="'reduceInstalledPackageSpaceUsage'" #TODO: Add other items you would configure here # https://docs.chocolatey.org/en-us/configuration #TODO: Are we installing the Chocolatey Agent Service? C4B Only # https://docs.chocolatey.org/en-us/agent/setup # choco upgrade chocolatey-agent -y --pre #choco feature disable --name="'showNonElevatedWarnings'" #choco feature enable --name="'useBackgroundService'" #choco feature enable --name="'useBackgroundServiceWithNonAdministratorsOnly'" #TODO: Check out other options and features to set at the url above. #TODO: Also make sure you set your sources to allow for self-service # Download and internalize packages. choco download chocolatey chocolatey.server dotnet4.6.1 chocolateygui --internalize --output-directory="$env:SystemDrive\choco-setup\packages" --source="'https://community.chocolatey.org/api/v2/'" # C4B / C4BTRIAL - use this choco download chocolatey.extension chocolatey-agent --internalize --output-directory="$env:SystemDrive\choco-setup\packages" --source="'https://licensedpackages.chocolatey.org/api/v2/'" ``` -------------------------------- ### Install Chocolatey with License Path (PowerShell) Source: https://docs.chocolatey.org/en-us/guides/organizations/new-organizational-deployment-guide/client-setup Installs Chocolatey CLI by downloading the setup script from a public URL and applies a provided license file. This script uses a license path argument to configure the installation. ```powershell & [scriptblock]::Create([System.Net.WebClient]::new().DownloadString( "https://raw.githubusercontent.com/chocolatey/choco-orgguide-scripts/refs/heads/main/ClientSetup.ps1" )) -LicensePath ~Downloadschocolatey.license.xml ``` -------------------------------- ### Install Chocolatey Package Example (PowerShell) Source: https://docs.chocolatey.org/en-us/chocolatey-install-ps1 This script demonstrates how to install a package using the Install-ChocolateyPackage helper function. It defines package name, download URLs for 32-bit and 64-bit systems, and the silent installation arguments. The function then handles the download and silent installation. ```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 ``` -------------------------------- ### Ansible Playbook for Chocolatey Client Setup Source: https://docs.chocolatey.org/en-us/c4b-environments/ansible/client-setup This Ansible playbook automates the setup of Chocolatey for Business on Windows hosts. It prompts for necessary information like license paths and Central Management details, validates the license, ensures .NET Framework 4.8 is installed, and then installs Chocolatey with specified configurations and features. It also supports installing the Chocolatey GUI. ```yaml --- - name: Chocolatey For Business Client Setup hosts: "{{ c4b_nodes }}" gather_facts: true vars_prompt: - name: license_path prompt: "Path to Chocolatey License File" private: no - name: ccm_fqdn prompt: "FQDN to access Chocolatey Central Management, e.g. ccm.example.com" private: no - name: ccm_client_salt prompt: "Client Salt for communicating with Chocolatey Central Management" private: yes - name: ccm_service_salt prompt: "Service Salt for communicating with Chocolatey Central Management" private: yes - name: nexus_password prompt: "Password for the ChocoUser account on Sonatype Nexus Repository" private: yes vars: # You can add more sources here. chocolatey_sources: - name: ChocolateyInternal url: "https://{{ nexus_fqdn | default(ccm_fqdn) }}:8443/repository/ChocolateyInternal/index.json" user: "{{ nexus_user | default('chocouser') }}" password: "{{ nexus_password | mandatory }}" # You can add more configuration settings here. chocolatey_config: - cacheLocation: C:\ProgramData\chocolatey\choco-cache - commandExecutionTimeoutSeconds: 14400 - backgroundServiceAllowedCommands: install,upgrade,uninstall # You can add more features to enable or disable here. chocolatey_features: - showNonElevatedWarnings: disabled - useBackgroundService: enabled - useBackgroundServiceWithNonAdministratorsOnly: enabled - allowBackgroundServiceUninstallsFromUserInstallsOnly: enabled - excludeChocolateyPackagesDuringUpgradeAll: enabled # If you'd prefer to use a non-latest version of Chocolatey, you can specify it here. chocolatey_version: latest # When set to true, deploys Chocolatey GUI and the Chocolatey GUI licensed extension. install_gui: true # An accessible copy of the Dotnet 4.8 installer. ndp48_location: https://download.visualstudio.microsoft.com/download/pr/2d6bb6b2-226a-4baa-bdec-798822606ff1/8494001c276a4b96804cde7829c04d7f/ndp48-x86-x64-allos-enu.exe tasks: - name: Ensure a valid Chocolatey for Business License block: - name: Get Chocolatey License ansible.builtin.set_fact: license_content: "{{ lookup('file', license_path) }}" when: license_content is not defined and license_path is defined delegate_to: localhost - name: Get Chocolatey License Expiration ansible.builtin.set_fact: license_expiry: "{{ license_content | regex_search('expiration=\".+?\"') | regex_replace('expiration=\"(.+)\"', '\\1') | trim() }}" when: license_content is defined delegate_to: localhost - name: Test License Expiry ansible.builtin.assert: that: - license_expiry is defined - license_expiry | to_datetime('%Y-%m-%dT%H:%M:%S.0000000') - license_expiry > ansible_date_time.iso8601 quiet: true when: license_expiry is defined delegate_to: localhost - name: Ensure choco-setup Directory ansible.windows.win_tempfile: state: directory suffix: choco-setup register: choco_setup - name: Ensure Dotnet 4.8 ansible.windows.win_powershell: parameters: NetFx48InstallerFile: "{{ ndp48_location | default('https://download.visualstudio.microsoft.com/download/pr/2d6bb6b2-226a-4baa-bdec-798822606ff1/8494001c276a4b96804cde7829c04d7f/ndp48-x86-x64-allos-enu.exe') }}" WorkingDirectory: "{{ choco_setup.path }}" script: | param($NetFx48InstallerFile, $WorkingDirectory) if ((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" -ErrorAction SilentlyContinue).Release -lt 528040) { Write-Warning ".NET Framework 4.8 is required for Chocolatey. Installing .NET Framework 4.8..." # Attempt to download the installer if it doesn't exist locally if (-not (Test-Path $NetFx48InstallerFile)) { try { $DownloadArgs = @{ Uri = $NetFx48InstallerFile OutFile = Join-Path $WorkingDirectory $(Split-Path $NetFx48InstallerFile -Leaf) UseBasicParsing = $true } if (-not (Test-Path $DownloadArgs.OutFile)) { Invoke-WebRequest @DownloadArgs -ErrorAction Stop } $NetFx48InstallerFile = $DownloadArgs.OutFile } catch { $Ansible.failed = $true throw "Could not download .NET Framework 4.8" } } # Install .NET Framework 4.8 try { $psi = New-Object System.Diagnostics.ProcessStartInfo $psi.WorkingDirectory = $WorkingDirectory $psi.FileName = $NetFx48InstallerFile $psi.Arguments = "/q /norestart" $s = [System.Diagnostics.Process]::Start($psi) $s.WaitForExit() ``` -------------------------------- ### Install Chocolatey Windows Service with Parameters Source: https://docs.chocolatey.org/en-us/create/functions/install-chocolateywindowsservice This example showcases installing a Windows service using a hashtable for parameters, including name, display name, and the service executable path. This approach is useful for complex configurations. ```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 ``` -------------------------------- ### Validate Sonatype Nexus Installation with Pester Source: https://docs.chocolatey.org/en-us/guides/organizations/setup-nexus-repository-oss-solution Runs a suite of Pester tests to validate the successful installation and configuration of the Sonatype Nexus Repository. This script uses the same arguments as the installation script to ensure consistency. ```powershell $repositoryArgs = @{ RepositoryProduct = 'Nexus' ProxyRepository = 'Fabrikam-Proxy' ProdRepository = 'Fabrikam-Prod' RawRepository = 'Fabrikam-Assets' Credential = (Get-Credential) # Please replace with your desired credentials } ./ValidateNexusRepository.ps1 @repositoryArgs ``` -------------------------------- ### Running Client Setup Script Source: https://docs.chocolatey.org/en-us/guides/organizations/new-organizational-deployment-guide/client-setup Executes the Chocolatey client setup script. This script installs and configures Chocolatey CLI and Agent. It accepts script arguments to customize the setup. The script can be run directly from the client machine. ```powershell .\ClientSetup.ps1 @ScriptArgs ``` -------------------------------- ### Install Chocolatey GUI with Specific Parameters Source: https://docs.chocolatey.org/en-us/chocolatey-gui/setup/installation This example demonstrates how to install Chocolatey GUI with specific configuration parameters, including enabling console output, disabling delayed search, and setting the outdated packages cache duration. These parameters are passed as a single string to the --params argument. ```bash choco install chocolateygui --params="'/ShowConsoleOutput=$true /UseDelayedSearch=$false /OutdatedPackagesCacheDurationInMinutes=120'" ``` -------------------------------- ### Install Chocolatey Windows Service Basic Example Source: https://docs.chocolatey.org/en-us/create/functions/install-chocolateywindowsservice This snippet demonstrates the basic usage of the Install-ChocolateyWindowsService function to install a Windows service. It requires the service name and the executable path. ```powershell Install-ChocolateyWindowsService ` -Name 'bob' ` -ServiceExecutablePath 'c:\somewhere\to\service.exe' ``` -------------------------------- ### Chocolatey Feature Command Examples Source: https://docs.chocolatey.org/en-us/choco/commands/feature Provides practical examples of the 'choco feature' command in action. These examples illustrate how to list all features, get a specific feature's status, disable a feature, and enable a feature. ```bash choco feature choco feature list choco feature get checksumFiles choco feature get --name=checksumFiles choco feature disable --name=checksumFiles choco feature enable --name=checksumFiles ``` -------------------------------- ### Install Chocolatey using PowerShell from cmd.exe Source: https://docs.chocolatey.org/en-us/choco/setup This method allows for repeatable installations and integration into source control. It downloads the install script and then executes it. No changes to PowerShell execution policy are required. ```batch @echo off SET DIR=%~dp0% ::download install.ps1 %systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "((new-object net.webclient).DownloadFile('https://community.chocolatey.org/install.ps1','%DIR%install.ps1'))" ::run installer %systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR%install.ps1' %*" ``` -------------------------------- ### Automate Development Environment Setup with PowerShell and Chocolatey Source: https://docs.chocolatey.org/en-us/guides/usage/development-environment-setup This PowerShell script automates the setup of a development environment by installing Chocolatey, Nuget, Ruby, and necessary gems. It also handles restoring Nuget packages and building the source code using Rake. The script includes a helper function to prompt the user before installing packages. ```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 Chocolatey if (Install-NeededFor 'chocolatey') { [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) } # install nuget, ruby.devkit, and ruby if they are missing cinst nuget.commandline if (Install-NeededFor 'ruby / ruby devkit') { cinst ruby.devkit cinst ruby --version 1.9.3.54500 } # perform ruby updates and get gems gem update --system gem install rake gem install bundler # restore the nuget packages $nugetConfigs = Get-ChildItem '.\' -Recurse | ?{$_.name -match "packages\.config"} | select foreach ($nugetConfig in $nugetConfigs) { Write-Host "restoring packages from $($nugetConfig.FullName)" nuget install $($nugetConfig.FullName) /OutputDirectory packages } rake ``` -------------------------------- ### Install Launchy with Override and Silent Arguments Source: https://docs.chocolatey.org/en-us/choco/setup Installs the Launchy package using Chocolatey with specific install options. It includes '--override' and '/VERYSILENT /NORESTART' arguments to control the installation behavior, preventing restarts and ensuring a silent process. ```puppet package {'launchy': ensure => installed, install_options => ['--override', '--installArgs','"', '/VERYSILENT','/NORESTART','"'], } ``` -------------------------------- ### Install Software from Downloaded ISO (PowerShell) Source: https://docs.chocolatey.org/en-us/guides/create/mount-an-iso-in-chocolatey-package This PowerShell script illustrates installing software from an ISO file downloaded from a specified URL. It utilizes the `Install-ChocolateyIsoPackage` function, requiring package details, the download URL, checksum information for integrity, and silent installation arguments. This approach is useful when the ISO is not bundled with the package. ```powershell $packageName= 'bob' $toolsDir = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)" $url = 'https://somewhere.com/file.iso' $packageArgs = @{ packageName = $packageName fileType = 'msi' url = $url file = 'setup.msi' file64 = 'x64\setup64.msi' silentArgs = "/qn /norestart" validExitCodes= @(0, 3010, 1641) softwareName = 'Bob*' checksum = '12345' checksumType = 'sha256' } Install-ChocolateyIsoPackage @packageArgs ``` -------------------------------- ### Install Chocolatey with Public Download and CCM (PowerShell) Source: https://docs.chocolatey.org/en-us/guides/organizations/new-organizational-deployment-guide/client-setup Installs Chocolatey CLI and Agent by downloading the setup script from a public URL. Requires specifying CCM URL and communication salts. This method is used when no internal repository is set up. ```powershell $ScriptArgs = @{ ChocolateyCentralManagementUrl = "https://ccm.example.org:24020/ChocolateyManagementService" ClientCommunicationSalt = "ClientCommunicationSalt" ServiceCommunicationSalt = "ServiceCommunicationSalt" } & [scriptblock]::Create([System.Net.WebClient]::new().DownloadString( "https://raw.githubusercontent.com/chocolatey/choco-orgguide-scripts/refs/heads/main/ClientSetup.ps1" )) @ScriptArgs ``` -------------------------------- ### Install Chocolatey.Server using PowerShell Source: https://docs.chocolatey.org/en-us/guides/organizations/organizational-deployment-guide This PowerShell script installs or upgrades the Chocolatey.Server package. It sets the execution policy to bypass for the current process and uses Chocolatey to install the server. It also provides a warning with links to further setup instructions. ```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://docs.chocolatey.org/en-us/guides/organizations/set-up-chocolatey-server#setup-normally and https://docs.chocolatey.org/en-us/guides/organizations/set-up-chocolatey-server#additional-configuration for now." # more may be added later ``` -------------------------------- ### Move Deployment Plan to Ready & Start Source: https://docs.chocolatey.org/en-us/central-management/usage/api/examples Transitions a deployment plan to a 'Ready' state and then initiates its execution. This is the final step to start the deployment. ```APIDOC ## POST /api/services/app/DeploymentPlans/MoveToReady & POST /api/services/app/DeploymentPlans/Start ### Description This section covers two sequential actions: first, moving a deployment plan to the 'Ready' state, making it available for execution, and second, starting the execution of a deployment plan. ### Method POST ### Endpoint - `/api/services/app/DeploymentPlans/MoveToReady` - `/api/services/app/DeploymentPlans/Start` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **id** (string) - Required - The ID of the deployment plan to affect. ### Request Example ```powershell # Move to Ready $params = @{ Uri = "https://$CcmServerHostname/api/services/app/DeploymentPlans/MoveToReady" Method = "POST" WebSession = $Session ContentType = 'application/json' Body = @{ id = $deployment.Id } | ConvertTo-Json } $null = Invoke-RestMethod @params # Start Deployment $params = @{ Uri = "https://$CcmServerHostname/api/services/app/DeploymentPlans/Start" Method = "POST" WebSession = $Session ContentType = 'application/json' Body = @{ id = $deployment.Id } | ConvertTo-Json } $null = Invoke-RestMethod @params ``` ### Response #### Success Response (200) No specific response body is detailed for these actions, indicating success is typically confirmed by the absence of errors. #### Response Example (Typically an empty object or a success status indicator if provided by the API) ```json { "success": true } ``` ``` -------------------------------- ### Install Chocolatey Agent Service with Conditional Logic Source: https://docs.chocolatey.org/en-us/create/functions/install-chocolateywindowsservice This advanced example installs the Chocolatey Agent service, incorporating logic to handle username, password, and background service upgrade scenarios. It conditionally sets parameters like 'DoNotReinstallService' based on environment variables or user input. ```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 backgound service for Chocolatey.' StartupType = 'Automatic' ServiceExecutablePath = $serviceExe Username = 'ChocolateyLocalAdmin' } $pp = Get-PackageParameters if ($pp['Username']) { $packageArgs['Username'] = $pp['Username'] } if ($pp['Password']) { $packageArgs['Password'] = $pp['Password'] } if ($pp['EnterPassword']) { $packageArgs['Password'] = Read-Host "Enter password for $($packageArgs['Username']):" -AsSecureString} if ($pp['UseDefaultChocolateyConfigUser']) { $packageArgs.Remove('Username') } # We don't want to shut down the service when we are running in background mode if ($env:ChocolateyBackgroundService -eq 'true') { Write-Warning "Detected running in background mode to upgrade the chocolatey-agent. Upgrade will attempt without restarting the service. \n Changes to service itself (like user/password) will be ignored." $packageArgs['DoNotReinstallService'] = $true } # Explicit request not to restart or reinstall the service. if ($pp['NoRestartService'] -or $pp['DoNotReinstallService']) { Write-Warning "Upgrade will attempt without restarting the service. \n Changes to service itself (like user/password) will be ignored." $packageArgs['DoNotReinstallService'] = $true } Install-ChocolateyWindowsService @packageArgs ``` -------------------------------- ### Install Chocolatey from Package (PowerShell) Source: https://docs.chocolatey.org/en-us/choco/setup This PowerShell code block handles the idempotency of Chocolatey installation. It first checks if Chocolatey is already installed by verifying the existence of a path (presumably related to the installation). If not installed, it downloads the Chocolatey package if it doesn't exist locally and then proceeds to install Chocolatey from the downloaded package. ```powershell # Idempotence - do not install Chocolatey if it is already installed if (!(Test-Path $ChocoInstallPath)) { # download the package to the local path if (!(Test-Path $localChocolateyPackageFilePath)) { Download-Package $searchUrl $localChocolateyPackageFilePath } # Install Chocolatey Install-ChocolateyFromPackage $localChocolateyPackageFilePath } ``` -------------------------------- ### Install .NET Frameworks Source: https://docs.chocolatey.org/en-us/guides/usage/development-environment-setup Installs multiple versions of the .NET Framework using Chocolatey with the 'webpi' source. This ensures compatibility with applications requiring specific .NET Framework versions. ```powershell Write-Host "Grabbing required frameworks" cinst netframework2 -source webpi cinst NETFramework35 -source webpi cinst NETFramework4 -source webpi cinst NETFramework4Update402 -source webpi cinst NETFramework4Update402_KB2544514_Only -source webpi cinst WindowsInstaller31 -source webpi cinst WindowsInstaller45 -source webpi ``` -------------------------------- ### Install Chocolatey with Puppet (Basic) Source: https://docs.chocolatey.org/en-us/choco/setup This Puppet code snippet demonstrates a basic way to include the Chocolatey module, which handles the installation of Chocolatey on Windows systems. This is a straightforward method for ensuring Chocolatey is present and managed by Puppet. ```puppet ## - Ensure Chocolatey Install - #include chocolatey ``` -------------------------------- ### Example: Initialize-C4bSetup.ps1 with Wildcard Certificate - PowerShell Source: https://docs.chocolatey.org/en-us/c4b-environments/quick-start-environment/chocolatey-for-business-quick-start-guide This example demonstrates how to execute `Initialize-C4bSetup.ps1` with a specific wildcard certificate thumbprint and a desired FQDN. This is useful for proof-of-concept environments using wildcard certificates. ```PowerShell Set-Location "$env:SystemDrive\choco-setup\files" .Initialize-C4bSetup.ps1 -Thumbprint deee9b2fabb24bdaae71d82286e08de1 -CertificateDnsName chocolatey.foo.org ``` -------------------------------- ### Install IIS Components Source: https://docs.chocolatey.org/en-us/guides/usage/development-environment-setup Installs a comprehensive set of Internet Information Services (IIS) components using Chocolatey with the 'webpi' source. This ensures the web server is configured with necessary features for hosting web applications. ```powershell if (Install-NeededFor 'IIS' $false) { cinst ASPNET -source webpi cinst ASPNET_REGIIS -source webpi cinst DefaultDocument -source webpi cinst DynamicContentCompression -source webpi cinst HTTPRedirection -source webpi cinst IIS7_ExtensionLessURLs -source webpi cinst IISExpress -source webpi cinst IISExpress_7_5 -source webpi cinst IISManagementConsole -source webpi cinst ISAPIExtensions -source webpi cinst ISAPIFilters -source webpi cinst NETExtensibility -source webpi cinst RequestFiltering -source webpi cinst StaticContent -source webpi cinst StaticContentCompression -source webpi cinst UrlRewrite2 -source webpi cinst WindowsAuthentication -source webpi } ``` -------------------------------- ### Run Initialize-C4bSetup.ps1 with Self-Signed Certificate - PowerShell Source: https://docs.chocolatey.org/en-us/c4b-environments/quick-start-environment/chocolatey-for-business-quick-start-guide This command executes the `Initialize-C4bSetup.ps1` script to set up C4B using a self-signed certificate. This method is suitable for bare-minimum proof-of-concept environments and does not require additional parameters. ```PowerShell Set-Location "$env:SystemDrive\choco-setup\files" .Initialize-C4bSetup.ps1 ``` -------------------------------- ### Install Sonatype Nexus Repository using PowerShell Source: https://docs.chocolatey.org/en-us/guides/organizations/setup-nexus-repository-c4b-solution Installs and configures Sonatype Nexus Repository with specified NuGet and Generic repositories. Requires environment information and user credentials for authentication. ```powershell $repositoryArgs = @{ ProdRepository = 'Fabrikam-Prod' TestRepository = 'Fabrikam-Test' RawRepository = 'Fabrikam-Assets' Credential = (Get-Credential) # Please replace with your desired credentials } $InstallScript = [System.Net.WebClient]::new().DownloadString('https://ch0.co/InstallNexusRepository.ps1') & ([Scriptblock]::Create($InstallScript)) @repositoryArgs ``` -------------------------------- ### Create Tutorials Directory Source: https://docs.chocolatey.org/en-us/guides/create/prepare-packaging-env Creates a new directory named 'tutorials' in the user's home directory using PowerShell. This directory will serve as a location for package creation tutorials. ```powershell New-Item ~\tutorials -ItemType Directory ``` -------------------------------- ### Chocolatey Agent Log Entry Example Source: https://docs.chocolatey.org/en-us/central-management/setup/client An example log entry from the Chocolatey Agent, indicating a successful connection to the CCM server for reporting. This is used during installation verification to confirm communication is established. ```log [INFO ] - Creating secure channel to https://ccmserver:24020/ChocolateyManagementService ahead of CCM check-in... ``` -------------------------------- ### Configure Sonatype Nexus Repository using PowerShell Source: https://docs.chocolatey.org/en-us/guides/organizations/setup-nexus-repository-oss-solution Configures a Sonatype Nexus Repository server with specific repository setups (proxy NuGet, production NuGet, raw) and credentials. This script automates the creation of various repository types and a dedicated user role for Chocolatey CLI authentication. ```powershell $repositoryArgs = @{ RepositoryProduct = 'Nexus' ProxyRepository = 'Fabrikam-Proxy' ProdRepository = 'Fabrikam-Prod' RawRepository = 'Fabrikam-Assets' Credential = (Get-Credential) # Please replace with your desired credentials } $InstallScript = [System.Net.WebClient]::new().DownloadString('https://ch0.co/InstallRepository.ps1') & ([Scriptblock]::Create($InstallScript)) @repositoryArgs ``` -------------------------------- ### License Chocolatey CLI Installation Source: https://docs.chocolatey.org/en-us/guides/organizations/setup-nexus-repository-c4b-solution Copies a license file to the Chocolatey license directory. Ensure 'YourLicenseFilePath' is replaced with the actual path to your license file. ```powershell $licenseDir = New-Item C:\ProgramData\chocolatey\license -ItemType Directory Copy-Item 'YourLicenseFilePath' -Destination $licenseDir ``` -------------------------------- ### Run Initialize-C4bSetup.ps1 with Custom SSL Certificate - PowerShell Source: https://docs.chocolatey.org/en-us/c4b-environments/quick-start-environment/chocolatey-for-business-quick-start-guide This command executes the `Initialize-C4bSetup.ps1` script using a custom SSL certificate. The `-Thumbprint` parameter must be replaced with the actual thumbprint of the SSL certificate located in the 'Local Machine > Trusted People' store. ```PowerShell Set-Location "$env:SystemDrive\choco-setup\files" .Initialize-C4bSetup.ps1 -Thumbprint '' ``` -------------------------------- ### Installing Additional Packages via Script Source: https://docs.chocolatey.org/en-us/guides/organizations/new-organizational-deployment-guide/client-setup Installs extra packages during the Chocolatey client setup process. The `-AdditionalPackages` parameter accepts an array of hashtables, each specifying a package by its `Id` and optionally `Version` and `Pin` status. For more complex installations, modifying the script directly is recommended. ```powershell .\ClientSetup.ps1 @ScriptArgs -AdditionalPackages @( @{ Id = 'firefox' Version = '144.0.0' Pin = $true } ) ``` -------------------------------- ### Setup PowerShell Tab Completion for Chocolatey Source: https://docs.chocolatey.org/en-us/choco/setup Configures the PowerShell environment to enable tab completion for Chocolatey commands. It ensures the directory for PowerShell profiles exists and creates or updates the PowerShell profile script. ```puppet file {'C:/Users/Administrator/Documents/WindowsPowerShell': ensure => directory, } file {'C:/Users/Administrator/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1': ensure => file, content => '$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" if (Test-Path($ChocolateyProfile)) { Import-Module "$ChocolateyProfile" }', } ``` -------------------------------- ### Run Initialize-C4bSetup.ps1 with Wildcard SSL Certificate - PowerShell Source: https://docs.chocolatey.org/en-us/c4b-environments/quick-start-environment/chocolatey-for-business-quick-start-guide This command runs the `Initialize-C4bSetup.ps1` script with a wildcard SSL certificate. It requires both the `-Thumbprint` of the certificate and the `-CertificateDnsName` for the desired Fully Qualified Domain Name (FQDN). ```PowerShell Set-Location "$env:SystemDrive\choco-setup\files" .Initialize-C4bSetup.ps1 -Thumbprint '' -CertificateDnsName '' ``` -------------------------------- ### Download and Internalize dotnet-aspnetcoremodule-v2 Package Source: https://docs.chocolatey.org/en-us/central-management/setup Downloads a specific version of the dotnet-aspnetcoremodule-v2 package using Chocolatey, internalizing it and its URLs, and saving it to a specified output directory. This command is used starting from v0.9.0 of the CCM Website package. ```bash choco download dotnet-aspnetcoremodule-v2 --version 18.0.24201 --force --internalize --internalize-all-urls --append-use-original-location --source="'https://community.chocolatey.org/api/v2/'" --output-directory="'C:\\packages'" ``` -------------------------------- ### Install Chocolatey CLI using PowerShell Source: https://docs.chocolatey.org/en-us/guides/organizations/setup-nexus-repository-c4b-solution Installs Chocolatey CLI by setting the execution policy and invoking a script from a URL. This is a prerequisite for licensing and further configuration. ```powershell Set-ExecutionPolicy Bypass -Scope Process -Force Invoke-RestMethod https://ch0.co/go | Invoke-Expression ``` -------------------------------- ### PowerShell: Verify Extension Installation Source: https://docs.chocolatey.org/en-us/guides/create/create-extension-package These PowerShell commands verify the installation of an extension package. The first command lists all installed extensions in the Chocolatey extensions directory, and the second command specifically checks for the 'example' directory, confirming the presence of the installed module. ```PowerShell # This should show an 'example' directory, along with all of your other installed extensions Get-ChildItem $env:ChocolateyInstall\extensions # This should show your module Get-ChildItem $env:ChocolateyInstall\extensions\example ``` -------------------------------- ### Install Chocolatey using NuGet.exe from PowerShell Source: https://docs.chocolatey.org/en-us/choco/setup This method uses the NuGet command line to download the Chocolatey package. After downloading, you navigate to the tools folder and execute the installation script via PowerShell. ```powershell nuget install chocolatey nuget install chocolatey -pre # Once downloaded, open PowerShell, navigate to the tools folder and run: & .\chocolateyInstall.ps1 ``` -------------------------------- ### Install Latest Version of Git Package Source: https://docs.chocolatey.org/en-us/choco/setup Ensures the latest version of the Git package is installed using Chocolatey. This is a straightforward installation of the most recent release. ```puppet package {'git': ensure => latest, } ``` -------------------------------- ### Install Chocolatey Package Manager Source: https://docs.chocolatey.org/en-us/guides/usage/development-environment-setup Installs the Chocolatey package manager if it's not already detected. This script downloads and executes the Chocolatey installation script from the official community repository. It ensures the system is ready to use Chocolatey for subsequent package installations. ```powershell if (Install-NeededFor 'chocolatey') { [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) } ``` -------------------------------- ### Install Local nupkg File with Chocolatey Source: https://docs.chocolatey.org/en-us/licensed-extension/setup Installs a licensed extension from a local .nupkg file. Requires specifying the path to the .nupkg file using the --source switch. The --pre switch can be used for pre-release versions. ```bash choco install chocolatey.extension --pre --source C:\folder\where\downloaded\nupkg\resides ``` -------------------------------- ### Install Chocolatey from downloaded NuGet package using PowerShell Source: https://docs.chocolatey.org/en-us/choco/setup This approach involves manually downloading the Chocolatey NuGet package, unzipping it, and then running the installation script from the extracted tools folder. Ensure PowerShell execution policy is set appropriately. ```powershell # After downloading, unzipping, and navigating to the tools folder: & .\chocolateyInstall.ps1 ``` -------------------------------- ### Install Universal Silent Switch Finder Source: https://docs.chocolatey.org/en-us/create/create-packages-quick-start Command to install the Universal Silent Switch Finder tool, which helps in identifying silent installation arguments for various installers. ```bash choco install ussf ``` -------------------------------- ### Example: Advanced Script Step for OS Version Source: https://docs.chocolatey.org/en-us/central-management/chococcm/functions/setccmdeploymentstep This example shows how to configure an advanced deployment step to gather OS version information using a PowerShell script block. It utilizes a hashtable for parameters and passes it to the cmdlet. ```powershell $stepParams = @{ Deployment = 'OS Version' Step = 'Gather Info' TargetGroup = 'US-East servers' Script = { $data = Get-WMIObject win32_OperatingSystem [pscustomobject]@{ Name = $data.caption Version = $data.version } } } Set-CCMDeploymentStep @stepParams ``` -------------------------------- ### Install Chocolatey with Internal Repository and CCM (PowerShell) Source: https://docs.chocolatey.org/en-us/guides/organizations/new-organizational-deployment-guide/client-setup Installs Chocolatey CLI and Agent, configuring it with an internal repository and Chocolatey Central Management. Requires specifying repository URL, credentials, CCM URL, and communication salts. This script downloads a client setup script from a specified repository URL. ```powershell $ScriptArgs = @{ RepositoryUrl = "NexusChocolateyCoreRepository" RepositoryCredential = [PSCredential]::new( "chocoPackager", (ConvertTo-SecureString "PackageUploadCredential" -AsPlainText -Force) ) ChocolateyCentralManagementUrl = "https://ccm.example.org:24020/ChocolateyManagementService" ServiceCommunicationSalt = "ServiceCommunicationSalt" ClientCommunicationSalt = "ClientCommunicationSalt" } $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 ``` -------------------------------- ### Install SQL Server Express and Management Studio Source: https://docs.chocolatey.org/en-us/guides/usage/development-environment-setup Installs SQL Server Express and SQL Server Management Studio using Chocolatey with the 'webpi' source. A warning is issued to the user about supplying a password for SQL Server Express during installation. ```powershell Write-Host "Checking for/installing SQLServer Express and Management Studio..." cinst SQLManagementStudio -source webpi cinst SQLExpressTools -source webpi Write-Host "Finished checking for/install SQLServer Express and Management Studio" ``` -------------------------------- ### Apply Chocolatey License Source: https://docs.chocolatey.org/en-us/guides/organizations/organizational-deployment-guide This code block shows how to add a Chocolatey license to the setup and local installation. It involves creating a directory for the license and copying the license file to the appropriate Chocolatey installation path. ```powershell 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 ``` -------------------------------- ### Set Up Chocolatey Simple Server Source: https://docs.chocolatey.org/en-us/licensed-extension/setup Configures a Chocolatey Simple Server by ensuring the 'chocolatey_server' class is applied with a specified package source. It also adds a local Chocolatey server source with a defined priority. ```Puppet class {"chocolatey_server": server_package_source => 'https://internalurl/odata/server', } chocolateysource {"local_chocolatey_server": ensure => present, location => 'http://localhost/chocolatey', priority => 2, } ``` -------------------------------- ### Install Multiple Latest Packages from Community Source Source: https://docs.chocolatey.org/en-us/choco/setup Installs the latest versions of a list of common development and utility packages from the community Chocolatey repository. This includes applications like Notepad++, Git Extensions, and Node.js. ```puppet package { ['virustotaluploader', 'googlechrome', 'notepadplusplus', '7zip', 'ruby', 'charles', 'grepwin', 'stexbar', 'inkscape', 'gitextensions', 'pandoc', 'snagit', 'nodejs', ]: ensure => latest, source => 'https://community.chocolatey.org/api/v2/', } ``` -------------------------------- ### Chocolatey Install Script for EXE Installers (PowerShell) Source: https://docs.chocolatey.org/en-us/create/create-packages-quick-start A PowerShell script snippet for the `chocolateyInstall.ps1` file to install software using an EXE installer. It defines the package name, installer type, silent arguments, and download URL. ```powershell $name = 'Package Name' $installerType = 'exe' $url = 'http://path/to/download/installer.exe' $silentArgs = '/VERYSILENT' Install-ChocolateyPackage $name $installerType $silentArgs $url ``` -------------------------------- ### Install Visual Studio Components Source: https://docs.chocolatey.org/en-us/guides/usage/development-environment-setup Installs various Visual Studio components and service packs using Chocolatey with the 'webpi' source. This includes Visual Studio Web Developer Edition and its service packs, as well as MVC 3 and its language packs. ```powershell Write-Host "Checking for/installing Visual Studio Items..." if (Install-NeededFor 'VS2010 Express & SP1' $false) { cinst VWD_RTW -source webpi cinst VWD2010SP1AzurePack -source webpi } if (Install-NeededFor 'VS2010 Full Edition SP1') { cinst VS2010SP1Pack -source webpi } cinst MVC3 -source webpi cinst MVC3Loc -source webpi Write-Host "Finished checking for/installing Visual Studio Items." ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.