Add Chocolatey Private Repo


# Set private repo source if it doesn't exist
function addRepo{

  function testUrl($url){
    $HTTP_Request = [System.Net.WebRequest]::Create($url)
    $HTTP_Response = $HTTP_Request.GetResponse()
    $HTTP_Status = [int]$HTTP_Response.StatusCode
    If ($HTTP_Status -eq 200) {
    }Else {
    If (!($HTTP_Response -eq $null)){ $HTTP_Response.Close()}
    return $valid
  # Install Chocolatey from the Intranet private repo
  [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12  
  if (!(Get-Command choco.exe -ErrorAction SilentlyContinue)){
    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(''))}
  $privateRepo="'$privateRepoName' -s '$privateRepoUrl' --priority=$priority"  
  $sources=choco source list
  $privateRepoExists=$sources -match $privateRepoName     
  if (!$privateRepoExists -and $(testUrl $privateRepoUrl)){
      invoke-expression "choco source add -n=$privateRepo"
      return $true
    write-host "Private repo $privateRepoName already exists on $env:computername." -foregroundcolor green
    return $True
    return $false
addRepo $privateRepo $privateRepoUrl $priority

Leave a Reply

Your email address will not be published. Required fields are marked *