Skip to content

Instantly share code, notes, and snippets.

@zsarge
Last active June 20, 2021 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zsarge/557280d9f8ee99315ce52b27498cf32a to your computer and use it in GitHub Desktop.
Save zsarge/557280d9f8ee99315ce52b27498cf32a to your computer and use it in GitHub Desktop.
This PowerShell script installs Node.JS v16.3.0 on Windows 10 without admin privileges.
# This powershell script installs Node.JS v16.3.0 without admin on Windows 10.
# See https://nodejs.org/en/download/ for direct download.
# A temporary path is created on your desktop called "DELETE_ME".
# Node is actually installed to %USERPROFILE%\node-v16.3.0-win-x64\
# Written by Zack Sargent on June 20th, 2021
$DesktopPath = [Environment]::GetFolderPath("Desktop")
$WorkPath = "$DesktopPath\DELETE_ME"
echo "Installing Node.JS ..."
$NodeName = "node-v16.3.0-win-x64"
$NodeURL = "https://nodejs.org/dist/v16.3.0/$NodeName.zip"
$NodeZipLocation = "$WorkPath\$NodeName.zip"
$InstallationDestination = "$env:userprofile"
$RealInstallPath = "$InstallationDestination\$NodeName"
# Remove path if it already exists, so that this script can be run repeatedly
If (Test-Path $WorkPath){
Remove-Item $WorkPath -Recurse
}
# Be very careful not to remove your user directory
If (Test-Path $RealInstallPath){
Remove-Item $RealInstallPath -Recurse
}
New-Item -ItemType directory -Path $WorkPath
Start-Transcript -Path "$WorkPath\transcript_$(Get-Date -Format "MM-dd-yyyy_HH-mm").txt" -NoClobber
echo "NodeURL = $NodeURL"
echo "NodeZipLocation = $NodeZipLocation"
echo ""
echo ""
# Download zip file:
echo "Downloading Node.JS binary."
echo "This may take a while..."
(New-Object System.Net.WebClient).DownloadFile($NodeURL, $NodeZipLocation)
echo ""
echo "Extracting from zip file..."
Expand-Archive $NodeZipLocation -DestinationPath $InstallationDestination
echo ""
echo "Add nodejs path to user Env:Path"
$CurrentPath = [Environment]::GetEnvironmentVariable("Path", "User")
$AppendedPath = "$CurrentPath;$RealInstallPath;"
[Environment]::SetEnvironmentVariable("Path", $AppendedPath, "User")
Start-Sleep -s 5 # hold screen open for a few seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment