PowerShell

From Dave-Wiki
Revision as of 15:04, 19 November 2023 by Dave (talk | contribs)
Jump to navigation Jump to search

General

Updating

  1. winget search Microsoft.PowerShell
  2. winget install --id Microsoft.PowerShell --source winget

Check Version

$PSVersionTable.PSVersion

Users

List users

net user

Change password of a local user account

net user [username] [new_password]

Enable or Disable a local user

net user [username] /active:yes (or no)

Network

Useful network information

net config workstation

Change a network interface to use dynamic DHCP to get its IP

netsh interface ip show config

netsh interface ip set address "Ethernet" dhcp

Reset a network interface

netsh int ip reset

netsh winsock reset

Release and renew an IP address

ipconfig /release & ipconfig /renew

Mount a Windows file share

net use \\path\to\shared\folder /user:<username>

Allow Insecure Logons to an SMB Share

Allows you to access Anonymous Linux SMB Shares

In gpedit.msc, enable:

Computer Configuration\Administrative Templates\Network\Lanman Workstation\Enable insecure guest logons

Add a static route

route add -p <dest-network> MASK <dest-mask> <next-hop-ip> METRIC 0 IF <iface-num>

Other

Text-to-speech

powershell Add-Type -AssemblyName System.speech; $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer; $speak.Speak('I am groot')

System Info

Get PC's serial number

wmic bios get serialnumber

wmic csproduct get vendor,name,identifyingnumber

Get Windows build number from an .iso file

dism /get-wiminfo /wimfile:g:\sources\install.wim

Then, run it again with whichever index number you want to display:

dism /get-wiminfo /wimfile:g:\sources\install.wim /index:3

Printers

List printers

wmic printer list brief

Group Policy / AD

List which GPO's are applied

rsop.msc (GUI version)

gpresult /r /scope computer (CLI version)

or save it to an html file with /h:

gpresult /h c:\gpresult.html

Disk / Filesystem

Format a disk

get-disk

note the disk number, then:

clear-disk -number 1 -removedata -removeoem (removes data partitions and OEM partitions)

new-partition -disknumber 1 -usemaximumsize

get-partition -disknumber 1 | set-partition -newdriveletter D

Certificates / SSL

Convert x.509 (PKCS#12) to PFX

openssl pkcs12 -export -out cert.pfx -inkey private.key -in cert.crt -certfile CACert.crt (-certfile is not required)