powershell.exe
. $env:
(technically: $env
is a PowerShell drive). PS> echo $env:userprofile
HKEY_CURRENT_USER\Environment
and HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
can be read and written like so: PS C:\> echo [environment]::getEnvironmentVariable("PATH", "user" ) PS C:\> echo [environment]::getEnvironmentVariable("PATH", "machine" ) PS C:\> [environment]::setEnvironmentVariable("A_VAR" , "a value" , "user") PS C:\> [environment]::setEnvironmentVariable("ANOTHER_VAR", "another value", "machine")
WM_SETTINGCHANGE
after changing or creating a variable because PowerShell is smart enough to do that without being asked. ~
) to the %UserProfile%
directory: PS C:\> dir ~
$psVersionTable
. -file | -f | Specify a script to be run by the Powershell interpreter. Value can be - which reads the «script» from stdin. Possibly to be combined with -noExit . |
-command | -c | Specify a command to be executed, then exit (unless -noExit is specified). Value can be a string, a script block or - . (See also Executing a PowerShell script in a cmd.exe batch file) |
-configurationName | -config | Specify configuration endpoint in which PowerShell is run. |
-customPipeName | Name for an additional IPC server (named pipe), used for debugging or other cross-process communication. | |
-encodedCommand | -e , -ec | Command is Base64 encoded. |
-executionPolicy | -ex , -ep | Sets the execution policy (which is stored in the environment variable $env:psExecutionPolicyPreference .) |
-inputFormat | -inp , -if | Description of data format that is sent to PowerShell. Possible values: text or xml (which is serliazed CLIXML format). |
-interactive | -i | Opens an interactive PowerShell session. (See also -nonInteractive ) |
-login | -l | Starts PowerShell as a login shell using /bin/sh . Only useful on Linux and macOS. Must be first parameter when used. |
-MTA , -STA | Start the shell using a multi-threaded/single-threaded apartment. Windows only. Defaults to -STA if not specified | |
-noExit | -noe | Do not exit after running startup commands. |
-noLogo | -nol | Do not show copyright banner at startup. Without -noLogo , PowerShell displays a copyright banner and, if executing the profile takes longer than 500 ms(?), it also prints Loading personal and system profiles took xyz ms. |
-nonInteractive | -noni | Non-interactive prompt |
-noProfile | -nop | Do not load the PowerShell profile. (see the automatic variable $profile ). |
-outputFormat | -o , -of | Specifies output format. Possible valueare text and XML (serialized CLIXML format). |
-settingsFile | -settings | Overrides system-wide powershell.config.json file (which, by default, is tored in the directory that is pointed at by $psHome ) |
-version | -v | Show used version of PowerShell. See also the automatic variable $psVersionTable . |
-windowStyle | -w | Window style for the session. Possible values are normal , minimized , maximized and hidden . |
-workingDirectory | -wd | Sets the initial working directory by executing set-location -literalPath … . (This parameter Seems to be available in PowerShell Core only) |
-help | -? , /? | Show help |
powershell.exe
) is -file
and -command
for Powershell 7 (pwsh.exe
). -c statement(s)
creates a new PowerShell process in which one or more PowerShell statement(s) are executed. -c
can be: -
(the commands are read from stdin) powershell -c 'write-host going to loop; foreach ($i in 1..10) { $i }; write-host loop is finished'
-c
, the new PowerShell session is terminated when it has finished evaluating the statements. This termination can be prevented by using the -noExit
parameter instead of the -c
parameter: PS C:\> $PID 95420 PS C:\> pwsh -c '$PID' 87390 PS C:\> $PID 95420 PS C:\> pwsh -noExit '$PID' 14464 PS C:\> $PID 14464 PS C:\> exit PS C:\> $PID 95420
-wd
sets the initial working directory. -noLogo
hides the startup banner. pwsh … {-all:$false}
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
while the 64-bit executable is found at C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
. PS C:\> $([System.Runtime.InterOpServices.Marshal]::SizeOf([System.IntPtr]::Zero)*8)
Hello world.
: PS C:\> ${c:\users\Rene\tq84.txt}="Hello World"
1kb 2mb 3gb 4tb 5pb
1kb
evaluates to 1024
, 1mb
to 1048576
etc. windows+x
-> i
cmd.exe
simply by entering powershell
psVersionTable.psEdition
). System.Management.Automation.ClrFacade
class contains all diverging code for «FullCLR» and «CoreCLR». winget.exe
: C:\> winget search PowerShell … C:\> winget install --id Microsoft.PowerShell --source winget
--scope user
, winget
reported it had found a version that is not the most recent one. &
) is the call operator. __PSLockdownPolicy
and its relationship to wldp.dll. set-strictMode -version 2
. help about_common*
, -confirm
, -whatIf
. .psc
files are PowerShell console files. They specify one or more PSSnapIns to load into memory at startup. [object]
, [psobject]
, [pscustomobject]
prompt
and tabCompletion
functions. BTW: is tabCompletion
replaced by psReadLine
? write-host ` foo ` bar ` baz
cmd.exe
. $ docker pull mcr.microsoft.com/powershell … mcr.microsoft.com/powershell:latest
$ docker run -it --name pwsh mcr.microsoft.com/powershell:latest PowerShell 7.4.2 PS /> which pwsh /opt/microsoft/powershell/7/pwsh PS /> grep PRETTY_NAME /etc/os-release PRETTY_NAME="Ubuntu 22.04.4 LTS" PS /> exit
$ docker start -i pwsh A new PowerShell stable release is available: v7.4.5 Upgrade now, or check out the release page at: https://aka.ms/PowerShell-Release?tag=v7.4.5
PS /> invoke-restMethod https://aka.ms/install-powershell.ps1 -outFile $env:temp/install-powershell.ps1 PS /> & $env:temp/install-powershell.ps1 … PowerShell has been installed at /root/.powershell PS /> /root/.powershell/pwsh PowerShell 7.4.5 PS /> mv /opt/microsoft/powershell/7/ /opt/microsoft/powershell/7.bak PS /> mv /root/.powershell/ /opt/microsoft/powershell/7 PS /> exit
$ docker start -i pwsh PowerShell 7.4.5
PS /> hostnamectl set-hostname pwsh-host hostnamectl: The term 'hostnamectl' is not recognized as a name of a cmdlet, function, script file, or executable program PS /> hostname pwsh-host hostname: you must be root to change the host name
PS /> id uid=0(root) gid=0(root) groups=0(root)
PS /> echo pwsh-host > /etc/hostname
PS /> git git: The term 'git' is not recognized as a name of a cmdlet, function, script file, or executable program. … PS /> apt update PS /> apt install -y git
PS /> useradd -s $(which pwsh) -m rene PS /> chpasswd rene:*** ^D
PS /> apt install -y sudo PS /> usermod -aG sudo rene
PS /> exit
$ docker start pwsh pwsh
$ docker exec --user rene -it pwsh /opt/microsoft/powershell/7/pwsh
docker exec --user rene -it pwsh /opt/microsoft/powershell/7/pwsh
conhost.exe
as child process (which is the console-host and controls the appearance and functionality of PowerShell). System.Management.Automation.PowerShell
Microsoft.PowerShell
namespace