functions/Install-Nuget.ps1

<#
    .SYNOPSIS
        Installs latest version of nuget
    .DESCRIPTION
        If not installed will download the latest copy of nuget and put it in the folder
    .PARAMETER fallbackNugetPath
        Location to store nuget
    .EXAMPLE
        Install-Nuget
    .NOTES
        FunctionName : Install-Nuget

        Created by : Sabin.io
    .LINK
#>

function Install-Nuget {
    [CmdletBinding()]
    param([string]$fallbackNugetPath="c:\Programdata\Nuget\Nuget.exe")
    Write-Verbose "Installing Nuget"

    if (Test-Path $fallbackNugetPath) {
        $nugetPath = $fallbackNugetPath
    }
    else {

        New-ToolPath (Split-Path $fallbackNugetPath -Parent);

        Write-Verbose "Downloading&Installing Nuget latest\"
        Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $fallbackNugetPath
        $nugetpath = $fallbackNugetPath
    }
    Write-Verbose "Nuget found $($env:nugetPath)"
    $env:nugetPath = $nugetpath
}