Windows OS
Windows Quirks
Collection of windows quirks
Con,aux,prn,lst,com0 to com9,Lpt0 to ltp9,nullcannot be used as name for files and folders in windows. Because all those names for device files in MS dosIn Excel 29th February 1900 is a valid date, which is not
PowerShell
PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language
PowerShell was made open-source and cross-platform with PowerShell Core, and can be installed on multiple operating systems
Install PowerShell Windows
PowerShell Remote Access Open new Remote Session:
Enter-PSSession -ComputerName <SERVER> -Credential <USERNAME>Environment Variables
Environment Variables can be used in PowerShell with the prefix $env:
Example:
- Variable:
%APPDATA% - In PowerShell:
$env:APPDATA - In CMD:
echo %APPDATA%
List of environment variables
| Variable | Description |
|---|---|
%ALLUSERSPROFILE% | C:\ProgramData |
%APPDATA% | C:\Users\{username}\AppData\Roaming |
%COMMONPROGRAMFILES% | C:\Program Files\Common Files |
%COMMONPROGRAMFILES(x86)% | C:\Program Files (x86)\Common Files |
%CommonProgramW6432% | C:\Program Files\Common Files |
%COMSPEC% | C:\Windows\System \cmdexe |
%HOMEDRIVE% | C:\ |
%HOMEPATH% | C:\Users\{username} |
%LOCALAPPDATA% | C:\Users\{username}\AppData\Local |
%LOGONSERVER% | \\{domain_logon_server} |
%PATH% | C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem |
%PathExt% | .com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc |
%PROGRAMDATA% | C:\ProgramData |
%PROGRAMFILES% | C:\Program Files |
%ProgramW6432% | C:\Program Files |
%PROGRAMFILES(X86)% | C:\Program Files (x86) |
%PROMPT% | $P$G |
%SystemDrive% | C: |
%SystemRoot% | C:\Windows |
%TEMP% | C:\Users\{username}\AppData\Local\Temp |
%TMP% | C:\Users\{username}\AppData\Local\Temp |
%USERDOMAIN% | Userdomain associated with current user |
%USERDOMAIN_ROAMINGPROFILE% | Userdomain associated with roaming profile |
%USERNAME% | {username} |
%USERPROFILE% | C:\Users\{username} |
%WINDIR% | C:\Windows |
%PUBLIC% | C:\Users\Public |
%PSModulePath% | %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\ |
%OneDrive% | C:\Users\{username}\OneDrive |
%DriverData% | C:\Windows\System32\Drivers\DriverData |
%CD% | Outputs current directory path (cmd) |
%CMDCMDLINE% | Outputs command line used to launch current Command Prompt session (cmd) |
%CMDEXTVERSION% | Outputs the number of current command processor extensions (cmd) |
%COMPUTERNAME% | Outputs the system name |
%DATE% | Outputs current date (cmd) |
%TIME% | Outputs time (cmd) |
%ERRORLEVEL% | Outputs the number of defining exit status of previous command (cmd) |
%PROCESSOR_IDENTIFIER% | Outputs processor identifier |
%PROCESSOR_LEVEL% | Outputs processor level |
%PROCESSOR_REVISION% | Outputs processor revision |
%NUMBER_OF_PROCESSORS% | Outputs the number of physical and virtual cores |
%RANDOM% | Outputs random number from 0 through 32767 |
%OS% | Windows_NT |
Chocolatey
Chocolatey is a machine-level, command-line package manager and installer for Windows software
Installation:
Check the Execution Policy:
- Run
Get-ExecutionPolicy - If it returns
Restricted, then runSet-ExecutionPolicy AllSignedorSet-ExecutionPolicy Bypass -Scope Process
- Run
Install Chocolatey:
powershellSet-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))Check if you install chocolatey
powershellchoco -?
- Install software package:
choco install <package>Certutil
Certutil.exe is a command-line program for Windows, installed as part of Certificate Services. You can use certutil.exe to dump and display certification authority (CA) configuration information, configure Certificate Services, backup and restore CA components, and verify certificates, key pairs, and certificate chains
# WIP
certutil -addstore -f "ROOT" new-root-certificate.crt
certutil -delstore "ROOT" serial-number-hexWSL
Backup and Restore WSL
Listing Running Distros:
powershellwsl --list --verboseStarting/Restarting a Distro:
powershellwsl --distribution DISTRO-NAMETerminate a Running Distro:
powershellwsl --t DISTRO-NAMETerminate All Running Distros and WSL process:
powershellwsl --shutdownBackup a WSL Distro:
powershellwsl --export (distribution) (filename.tar)Restore a WSL Distro from Backup:
powershellwsl --import (distribution) (install location) (file location and filename)
Symbolic Links
Link
.sshfolder:bashsudo ln -s /mnt/c/Users/lempa/.ssh ~/.sshLink
.kubefolder:bashsudo ln -s /mnt/c/Users/lempa/.ssh ~/.ssh
File Permissions
Advanced settings configuration in WSL: WSL Config Parameters
Example: wsl.conf
[automount]
enabled = true
options = "metadata,uid=1000,gid=1000,umask=077,fmask=11,case=off"
mountFsTab = true
[interop]
enabled = false
appendWindowsPath = falseNetworking
PortForwarding
Find IP Address
powershellbash.exe -c "ifconfig eth0 | grep 'inet '"Add PortForwarding
powershell$port = 8080 $remoteaddr = 0.0.0.0 netsh interface portproxy add v4tov4 listenport=$port connectport=$port connectaddress=$remoteaddr netsh advfirewall firewall add rule name=$port dir=in action=allow protocol=TCP localport=$portDelete PortForwarding
PowerShell$port = 8080 netsh interface portproxy delete v4tov4 listenport=$port netsh advfirewall firewall delete rule name=$portShow PortForwarding
powershellnetsh interface portproxy show v4tov4
Linux desktop in WSL2
With WSL2 it's possible to install and run a Linux desktop environment (XFCE)
- Tutorial Running XFCE Linux Desktop on WSL2 to run GUI applications in WSL2
Windows Updates
- Install Windows Update:
Install-Module -Name PSWindowsUpdate- List all Commands:
Get-Command -module PSWindowsUpdate
Get-WUInstall