============ PowerShell 5.1 commands history ============ $PSVersionTable.PSVersion check Version ---------- temporary (current session) history ---------- Get-History Clear-History Invoke-History Check Current Session History Count: (Get-History).Count Search Command in Current Session Get-History | Where-Object CommandLine -Match "keyword" ---------- Persistent command history file ---------- (Get-PSReadLineOption).HistorySavePath Fetch history file path ConsoleHost_history.txt History File Name History File Directory C:\Users\Malik Adil\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ Open History File: notepad (Get-PSReadLineOption).HistorySavePath Open History File Directory: explorer $env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine Clear Persistent History File: Remove-Item (Get-PSReadLineOption).HistorySavePath Change History Size: Set-PSReadLineOption -MaximumHistoryCount 10000 Check Maximum History Count: (Get-PSReadLineOption).MaximumHistoryCount Check Persistent History Count: (Get-Content (Get-PSReadLineOption).HistorySavePath).Count Check Actual History File Size (KB): "{0:N2} KB" -f ((Get-Item (Get-PSReadLineOption).HistorySavePath).Length / 1KB) Disable Saving History: Set-PSReadLineOption -HistorySaveStyle SaveNothing Search Command in persistent history file Select-String -Path (Get-PSReadLineOption).HistorySavePath -Pattern "keyword" Delete specific command: $path = (Get-PSReadLineOption).HistorySavePath (Get-Content $path) | Where-Object {$_ -notmatch "keyword"} | Set-Content $path ==================== WSL Windows Subsystem for Linux activation: ==================== Run these commands in Powershell Admin Mode Only 1. Enable the Windows Subsystem for Linux dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart 2. Enable Virtual Machine feature dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart 3. Download the Linux kernel update package wsl.exe --install OR wsl.exe --update 4. Set WSL 2 as your default version wsl --set-default-version 2 5. Install your Linux distribution of choice from microsoft store *************Update kali-linux and install the kali-win-kex from Linux to support running the GUI in WSL************* ---------install kex--------- sudo apt update sudo apt upgrade sudo apt install -y kali-win-kex ---------Jack up the install to everything--------- sudo apt install -y kali-linux-large Execute as you from Linux to bring up the Linux GUI kex-win-s ---------Run Kali Linux GUI from CMD--------- wsl -d kali-linux kex-win -s • Ref: https://www.kali.org/docs/wsl/win-kex/ C:\Users\Adil Awan>wsl -l --running to check which linux distro is running Windows Subsystem for Linux Distributions: kali-linux (Default) C:\Users\Adil Awan>wsl -t kali-linux to terminate the kali session C:\Users\Adil Awan>wsl -t ubuntu to terminate the ubuntu session C:\Users\Adil Awan>wsl -l -v to check installed linux distros' version NAME STATE VERSION * kali-linux Stopped 1 unregister Unregisters the distribution and deletes the root filesystem. PS C:\Users\Adil Awan> wsl --set-version kali-linux 2 Conversion in progress, this may take a few minutes... For information on key differences with WSL 2 please visit https://aka.ms/wsl2 sudo apt-get install telnet ------------------------NIC Teaming on client machines----------------------- New-NetSwitchTeam -Name "SwitchTeam01" -TeamMembers "Ethernet 2","Ethernet 3" ---->>>> Create NIC teaming Remove-NetSwitchTeam -Name "SwitchTeam01" ---->>>> Remove NIC teaming ------------------------NIC Teaming on server machines----------------------- NETLBFO Add-NetLbfoTeamMember Adds a new member (network adapter) to a specified NIC team Add-NetLbfoTeamNic Adds a new interface to a NIC team. Get-NetLbfoTeam Gets a list of NIC teams on the system. Get-NetLbfoTeamMember Gets network adapters that are members of a NIC team. Get-NetLbfoTeamNic Gets a list of team interfaces. New-NetLbfoTeam Creates a new NIC team. Remove-NetLbfoTeam Removes the specified NIC team from the host. Remove-NetLbfoTeamMember Removes one or more network adapters from a NIC team. Remove-NetLbfoTeamNic Removes a team interface from a NIC team. Rename-NetLbfoTeam Set-NetLbfoTeam Renames a NIC team Sets parameters on the specified NIC team. Set-NetLbfoTeamMember Sets the role of a member network adapter in a NIC team. Set-NetLbfoTeamNic Sets a new VLAN id on a team interface, or restores the interface to Default mode. cmd /c 'netstat -ano | find "3389"' to check which program or service uses the specified port number Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "PortNumber" Change RDP port Get-NetIPInterface to show network interfaces status -------------------------Network commands------------------------------- Get-NetConnectionProfile Set-NetConnectionProfile -Name "FiberNetAdil" -NetworkCategory Private Get-NetAdapterHardwareInfo Invoke-WebRequest ifconfig.me/ip Check Public IP Address, detailed (Invoke-WebRequest ifconfig.me/ip).Content Check Public IP Address, only IP Find-NetRoute Get-NetRoute New-NetRoute Remove-NetRoute Set-NetIPInterface Set-NetRoute set-netroute -protocol Rip SYNTAX Set-NetRoute [[-DestinationPrefix] ] [-AddressFamily {IPv4 | IPv6}] [-AsJob] [-CimSession ] [-Confirm] [-IncludeAllCompartments] [-InterfaceAlias ] [-InterfaceIndex ] [-NextHop ] [-PassThru] [-PolicyStore ] [-PreferredLifetime ] [-Protocol {Other | Local | NetMgmt | Icmp | Egp | Ggp | Hello | Rip | IsIs | EsIs | Igrp | Bbn | Ospf | Bgp | Idpr | Eigrp | Dvmrp | Rpl | Dhcp}] [-Publish {No | Age | Yes}] [-RouteMetric ] [-ThrottleLimit ] [-ValidLifetime ] [-WhatIf] [] -PolicyStore Specifies a PolicyStore value. The cmdlet changes the PolicyStore value to the value that you specify. The acceptable values for this parameter are: ActiveStore. The IP address information is valid. PersistentStore. The computer saves IP address information across restarts. When the computer restarts, it copies the saved settings to the ActiveStore. Specify ActiveStore only. If you do not specify this parameter, the default entries are created in both the ActiveStore and the PersistentStore. ------------------- IP Configs ------------------ Get-NetAdapter Get-NetIPAddress -InterfaceAlias "Ethernet" --------------- DNS Commands --------------- ipconfig /displaydns ipconfig /flushdns nslookup [IP or Domain name] ipconfig /displaydns ipconfig /displaydns > dns-cache.txt ipconfig /displaydns > %USERPROFILE%\Desktop\dns-cache.txt ipconfig /flushdns ipconfig /registerdns ipconfig /all nslookup google.com nslookup google.com 8.8.8.8 nslookup 8.8.8.8 ping google.com -------------------------------------------- Get-DnsClientCache Get-DnsClientCache | Out-File "$env:USERPROFILE\Desktop\dns-cache.txt" Clear-DnsClientCache Get-DnsClientServerAddress Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("8.8.8.8","1.1.1.1") Resolve-DnsName google.com Test-NetConnection google.com -Port 53 ------------------------------------------- -------------------------------system hardware commands---------------------------- Get-CimInstance Win32_Processor | Select Name CPU name (Get-CimInstance Win32_Processor).NumberOfCores no of core (Get-CimInstance Win32_Processor).NumberOfLogicalProcessors no of logcal processors wmic bios get smbiosbiosversion bios version