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 ( [String]$NewDir ) $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:
SendMessage (HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment")
There is another registry key HKEY_CURRENT_USER\Environment
that can also be
used.
setx
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
Start-Process ` -FilePath go.exe ` -NoNewWindow ` -ArgumentList ('run', 'cli/tools/server/cmd/server.go') ` -PassThru
Install Python
$url = https://www.python.org/ftp/python/3.6.3/python-3.6.3-amd64.exe Invoke-WebRequest -Uri $url -OutFile pythoninstaller.exe ./pythoninstaller.exe /quiet ` InstallAllUsers=1 ` PrependPath=1 ` Include_test=0 ` Include_doc=0 ` Include_tcltk=0
Upgrade Powershell
$scriptUri = https://raw.githubusercontent.com/jborean93/ansible-windows/master/scripts/Upgrade-PowerShell.ps1 Invoke-WebRequest -Uri $scriptUri