Just stashing this here in prep for a larger article.
# Modern websites require TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Do we want to install it for the complete machine? Otherwise install it within the user profile.
$IsMachine = $true
if ( $IsMachine ) {
$UtilPath = "C:\UTILS" # System-Level
}
else {
$UtilPath = Join-Path -Path ( $env:LOCALAPPDATA ) -ChildPath "Utils"
}
if ( -not ( Test-Path -Path $UtilPath ) )
{
Write-Host "Creating Utility Folder at [$UtilPath]" -ForegroundColor Yellow
New-Item -ItemType Directory -Path $UtilPath | Out-Null
}
#region Copy the SysInternals Tools
<#
Note: In some environments, the SysInternal tools are considered possible security risks. You have been warned.
#>
Write-Host "[BEGIN] Sysinternals Tools" -ForegroundColor Green
Write-Host "`tDownloading SysInternals ZIP"
Invoke-WebRequest -Uri "https://download.sysinternals.com/files/SysinternalsSuite.zip" -OutFile "$env:TEMP\SysinternalsSuite.zip"
Write-Host "`tExtracting Contents to [$UtilPath]"
Expand-Archive -Path "$env:TEMP\SysinternalsSuite.zip" -DestinationPath $UtilPath -Force
Write-Host "[COMPLETE] Sysinternals Tools" -ForegroundColor Green
#endregion Copy the SysInternals Tools
#region Download and Copy the Unix Utils for Windows
<#
Note: The Unix Utils are frequently aliases from modern PowerShell, but I still like using the originals.
#>
Write-Host "[BEGIN] Unix Utils from SourceForge" -ForegroundColor Green
Write-Host "`tDownloading the Unix Utils for Windows ZIP file"
Invoke-WebRequest -Uri "https://managedway.dl.sourceforge.net/project/unxutils/unxutils/current/UnxUtils.zip" -OutFile "$env:TEMP\UnxUtils.zip"
Write-Host "`tExpanding the Unix Utils ZIP"
Expand-Archive -Path "$env:TEMP\UnxUtils.zip" -DestinationPath "$env:TEMP\UnxUtils\" -Force
Write-Host "`tCopying the Unix Utils to [$UtilPath]"
Get-ChildItem -Path "$env:TEMP\UnxUtils\usr\local\wbin" | Copy-Item -Destination $UtilPath -Force
Write-Host "[COMPLETED] Unix Utils from SourceForge" -ForegroundColor Green
#endregion Download and Copy the Unix Utils for Windows
#region Get putty.exe
<#
Note: PuTTY is nearly universally loved for creating SSH connections.
If you prefer something else that offers a slightly more user-friendly format, I can recommend Solar-PuTTY.
Link: https://thwack.solarwinds.com/free-tools-trials#ft-solar-putty
#>
Write-Host "[BEGIN] Download PuTTY ZIP for Windows" -ForegroundColor Green
Write-Host "`tDownloading PuTTY ZIP file"
if ( [System.Environment]::Is64BitOperatingSystem ) {
Invoke-WebRequest -Uri "https://the.earth.li/~sgtatham/putty/latest/w64/putty.zip" -OutFile "$env:TEMP\putty.zip"
} else {
Invoke-WebRequest -Uri "https://the.earth.li/~sgtatham/putty/latest/w32/putty.zip" -OutFile "$env:TEMP\putty.zip"
}
Write-Host "`tExtracting Contents to [$UtilPath]"
Expand-Archive -Path "$env:TEMP\putty.zip" -DestinationPath $UtilPath -Force
Write-Host "[COMPLETED] Download Putty for Windows" -ForegroundColor Green
#endregion Get putty.exe
#region add Utility Folder to Path
if ( $IsMachine ) {
$PathVariable = [Environment]::GetEnvironmentVariable("Path", "Machine")
}
else {
$PathVariable = [Environment]::GetEnvironmentVariable("Path", "User")
}
if ( $PathVariable -notlike "*$( $UtilPath )*" ) {
$PathVariable += ";$UtilPath;"
$PathVariable = $PathVariable.Replace(";;", ";")
Write-Host "Adding [$UtilPath] to the Machine Path Variable" -ForegroundColor Yellow
Write-Host "You must close and reopen any command prompt windows to include to the new path"
if ( $IsMachine ) {
[Environment]::SetEnvironmentVariable("Path", $PathVariable, "Machine")
}
else {
[Environment]::SetEnvironmentVariable("Path", $PathVariable, "User")
}
} else {
Write-Host "[$( $UtilPath )] already contained in $( if ( $IsMachine ) {"machine " } else { "user " } ) environment variable 'Path'"
}
#endregion add Utility Folder to Path
As written the above will install the utilities in C:\UTILS
. However, some workstations may block these types of installs. In that event, I’ve added a flag ($IsMachine
) which can be flipped to False and install in the current user’s profile.
1 thought on “Installing Utilities Folder with PowerShell”