1 $VSN = "1.2.0"
2 
3 # build the filename for the Zip archive and exe file
4 $FileName = "cidr2range_$($VSN)_windows_amd64"
5 $ZipFileName = "$($FileName).zip"
6 
7 # download and extract zip
8 Invoke-WebRequest -Uri "https://github.com/ipinfo/cli/releases/download/cidr2range-$VSN/$FileName.zip" -OutFile ./$ZipFileName
9 Unblock-File ./$ZipFileName
10 Expand-Archive -Path ./$ZipFileName  -DestinationPath $env:LOCALAPPDATA\ipinfo -Force
11 
12 # delete if already exists
13 if (Test-Path "$env:LOCALAPPDATA\ipinfo\cidr2range.exe") {
14     Remove-Item "$env:LOCALAPPDATA\ipinfo\cidr2range.exe"
15 }
16 Rename-Item -Path "$env:LOCALAPPDATA\ipinfo\$FileName.exe" -NewName "cidr2range.exe"
17 
18 # setting up env.
19 $PathContent = [Environment]::GetEnvironmentVariable('path', 'Machine')
20 $IPinfoPath = "$env:LOCALAPPDATA\ipinfo"
21 
22 # if Path already exists
23 if ($PathContent -ne $null) {
24     if (-Not($PathContent -split ';' -contains $IPinfoPath)) {
25         [System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";$env:LOCALAPPDATA\ipinfo", "Machine")
26     }
27 }
28 else {
29     [System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";$env:LOCALAPPDATA\ipinfo", "Machine")
30 }
31 
32 # cleaning files
33 Remove-Item -Path ./$ZipFileName
34 "You can use cidr2range now."
35