Windows Stuff

I don't have a Windows machine so I don't test these notes, ever. Some of what I wrote here doesn't look like it makes much sens. But I guess if I wrote it down, it must have been useful at the time!

Environment Variables

List all env vars

gci env: | sort name

Function to update env variable

This is an attempt at a function to update environment variables permanently. It correctly sets a registry key, but it only takes effect after a reboot.

Function global:Add-Path()
    Param (

    $RegKey = 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment'
    $OldPath=(Get-ItemProperty -Path "$RegKey" -Name PATH).Path
    $NewPath = $OldPath + ';' + $NewDir
    Set-ItemProperty -Path "$RegKey" -Name PATH –Value $NewPath
    Return $NewPath

It's potentially possible to use SendMessage to update the environment for currently-running processes. It would look something like:


There is another registry key HKEY_CURRENT_USER\Environment that can also be used.


setx can set an environment variable and persist it, but it will only be available to new processes.

setx /m FOO bar

If you need the env var in the sshd environment, restart sshd:

Stop-Service sshd
Start-Service sshd

Background Process


Start-Process `
  -FilePath go.exe `
  -NoNewWindow `
  -ArgumentList ('run', 'cli/tools/server/cmd/server.go') `

Kill a Process

Install Python

$url =
Invoke-WebRequest -Uri $url -OutFile pythoninstaller.exe

./pythoninstaller.exe /quiet `
  InstallAllUsers=1 `
  PrependPath=1 `
  Include_test=0 `
  Include_doc=0 `

Upgrade Powershell

$scriptUri =
Invoke-WebRequest -Uri $scriptUri