Commands of Windows PowerShell or Command Prompt

AuthorCreatedModifiedFormat
Xin Li[2022-06-30 Thu 20:24:47][2023-09-08 Fri 01:01:47]org-mode

Table of Contents

  1. WSL
  2. Policy
  3. Environment
  4. Profile
  5. VPN
  6. SSH
  7. SMB1Protocol
  8. History
  9. Git
  10. Port Forwarding and Network
  11. Audio server
  12. Display Encryption State
  13. Footnotes

WSL

wsl --update --status
wsl --update
wsl --shutdown
wsl --list --all
wsl -l -v
wsl cat /proc/version
PowerShell

Policy

Set-PSReadLineOption -EditMode Emacs

Get-ExecutionPolicy
Get-ExecutionPolicy -List

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope UserPolicy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
PowerShell

Environment

test-path $profile
New-Item -Path $profile -Type File -Force

alias
sal
Set-Alias l ls
Set-Location ..

set devmgr_show_nonpresent_devices=1
start devmgmt.msc
cd ${env:USERPROFILE}

pip install img2pdf pdfkit beautifulsoup4 fpdf
PowerShell

Profile

# Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# New-Item -Path $profile -Type File -Force
# C:\Users\x\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Set-PSReadLineOption -EditMode Emacs
Set-Alias l ls
Set-Alias p python
Set-Alias e runemacs
function wslrun { C:\Users\x\AppData\Local\Microsoft\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_8wekyb3d8bbwe\wslg.exe -d Ubuntu --cd "~/work" -- $args }
function wslemacs { wslrun /usr/bin/emacs $args }
function wslmpv { wslrun /usr/bin/mpv $args }
function gst { git status }
function .. { Set-Location .. }
PowerShell

VPN

Install-Module -Name VPNCredentialsHelper
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
Import-Module VPNCredentialsHelper
Add-VpnConnection -Name "ConnectionName" -ServerAddress "server.address" -TunnelType "Ikev2" -AuthenticationMethod "Eap" -RememberCredential
Set-VpnConnectionUsernamePassword -connectionname "ConnectionName" -username "username" -password "password"
PowerShell

SSH

Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
ssh
sshd
PowerShell

SMB1Protocol

DISM /Online /Enable-Feature /All /FeatureName:SMB1Protocol
PowerShell

History

history
cd .\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\
cat .\ConsoleHost_history.txt
PowerShell

Git

Install-Module -Name Git
Import-Module Git
Get-Module
Invoke-Gitk
Update-GitBranch
# or
winget install --id Git.Git -e --source winget
PowerShell

Port Forwarding and Network

netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=22 connectaddress=172.19.110.110 connectport=22
netsh advfirewall firewall add rule name="Open Port 22 for WSL2" dir=in action=allow protocol=TCP localport=22
netsh interface portproxy show v4tov4
netsh interface ipv4 show interface
netsh interface ipv4 show subinterface

nslookup
ipconfig /all

Restart-NetAdapter -Name 'vEthernet (WSL)'

route print
route /p add 172.19.110.0 mask 0.0.0.0 192.160.100.1
route /p delete 172.19.110.0 mask 0.0.0.0 192.160.100.1

Set-NetIPInterface
Set-NetIPInterface -InterfaceIndex 34 -InterfaceMetric 36
Get-NetIPInterface

Set-NetIPConfiguration -InterfaceAlias "*WSL*"
Set-NetIPConfiguration -InterfaceAlias "*WSL*" DNSServer 8.8.8.8
Get-NetIPConfiguration -InterfaceAlias "*WSL*"

Restart-Service LxssManager
PowerShell

Audio server

.\scsynth.exe
.\scsynth.exe -t 32342
.\scsynth.exe -t 57110
.\scsynth.exe -t 57110 -B 0.0.0.0
.\scsynth.exe -u 57110 -B 0.0.0.0
.\scsynth.exe -u 57110
.\scsynth.exe -u 57110 -B 0.0.0.0
.\scsynth.exe -u 57110 -B 0.0.0.0 -i 0

.\pulseaudio.exe
.\pulseaudio.exe --help
PowerShell

Display Encryption State

Run cipher /u /n and get the output below.1

このシステムの暗号化されたファイル:

C:\Users\username\AppData\Local\Microsoft\IME\15.0\IMEJP\Dicts\{320**977-****-****-****-*2693095538D}_{EF5**D27-****-****-****-*2D12D5F7B12}.dctr
C:\Users\username\AppData\Local\Microsoft\IME\15.0\IMEJP\Dicts\{5F6**DF4-****-****-****-*517E31AF0D3}_{E1D**D8D-****-****-****-*E7ABFC134DF}.dctr
C:\Users\username\AppData\Local\Microsoft\IME\15.0\IMEJP\Dicts\{6FD**568-****-****-****-*B54C6DC43CF}_{2B1**93D-****-****-****-*1BEA5F107B6}.dctr
C:\Users\username\AppData\Local\Microsoft\IME\15.0\IMEJP\Dicts\{CA5**DBF-****-****-****-*D695AFAD2FD}_{3AF**65D-****-****-****-*D6687CDDA7E}.dctr
PowerShell

Footnotes

Backlinks