Skip to content

Instantly share code, notes, and snippets.

@codebytes
Last active July 14, 2024 01:10
Show Gist options
  • Select an option

  • Save codebytes/1ae354e736c88adef5b6f802597e3101 to your computer and use it in GitHub Desktop.

Select an option

Save codebytes/1ae354e736c88adef5b6f802597e3101 to your computer and use it in GitHub Desktop.

Revisions

  1. codebytes revised this gist Jul 5, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nuget-install.ps1
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    $sourceNugetExe = "http://nuget.org/nuget.exe"
    $sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
    $targetPath = "C:\Program Files\nuget"

    if (-not (Test-Path -LiteralPath $targetPath)) {
  2. codebytes revised this gist Jul 5, 2021. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions nuget-install.ps1
    Original file line number Diff line number Diff line change
    @@ -23,14 +23,14 @@ if (-not (Test-Path -LiteralPath "$targetPath\nuget.exe")) {
    "nuget.exe already exists at $targetPath"
    }
    # Add the tools dir to the path which directly contains NuGet.exe and CredentialProvider.VSS.exe
    if (!($env:Path -like "*$targetPath;*"))
    if (!($env:Path -like "*;$targetPath*"))
    {
    "Adding $targetPath to Path"
    $env:Path = "$targetPath;" + $env:Path

    $originalpaths = (Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment -Name PSModulePath).PSModulePath
    $newPath=$originalpaths+";$targetPath"
    Set-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment -Name PSModulePath –Value $newPath
    $oldPath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name path).path
    $newPath=$oldPath+";$targetPath"
    Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name path -Value $newPath
    }
    else {
    "$targetPath already existed in Path"
  3. codebytes created this gist Jul 5, 2021.
    37 changes: 37 additions & 0 deletions nuget-install.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    $sourceNugetExe = "http://nuget.org/nuget.exe"
    $targetPath = "C:\Program Files\nuget"

    if (-not (Test-Path -LiteralPath $targetPath)) {

    try {
    New-Item -Path $targetPath -ItemType Directory -ErrorAction Stop | Out-Null #-Force
    }
    catch {
    Write-Error -Message "Unable to create directory '$targetPath'. Error was: $_" -ErrorAction Stop
    }
    "Successfully created directory '$targetPath'."

    }
    else {
    "$targetPath already existed"
    }

    if (-not (Test-Path -LiteralPath "$targetPath\nuget.exe")) {
    "Downloading nuget.exe to $targetPath\nuget.exe"
    Invoke-WebRequest $sourceNugetExe -OutFile "$targetPath\nuget.exe"
    } else {
    "nuget.exe already exists at $targetPath"
    }
    # Add the tools dir to the path which directly contains NuGet.exe and CredentialProvider.VSS.exe
    if (!($env:Path -like "*$targetPath;*"))
    {
    "Adding $targetPath to Path"
    $env:Path = "$targetPath;" + $env:Path

    $originalpaths = (Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment -Name PSModulePath).PSModulePath
    $newPath=$originalpaths+";$targetPath"
    Set-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment -Name PSModulePath –Value $newPath
    }
    else {
    "$targetPath already existed in Path"
    }