PowerShell: Difference between revisions
No edit summary |
No edit summary |
||
Line 23: | Line 23: | ||
<code>net user [username] /active:yes</code> (or no) | <code>net user [username] /active:yes</code> (or no) | ||
=Network= | |||
==Useful network information== | |||
<code>net config workstation</code> | |||
==Change a network interface to use dynamic DHCP to get its IP== | |||
<code>netsh interface ip show config</code> | |||
<code>netsh interface ip set address "Ethernet" dhcp</code> | |||
==Reset a network interface== | |||
<code>netsh int ip reset</code> | |||
<code>netsh winsock reset</code> | |||
==Release and renew an IP address== | |||
<code>ipconfig /release & ipconfig /renew</code> | |||
==Mount a Windows file share== | |||
<code>net use \\path\to\shared\folder /user:<username></code> | |||
==Allow Insecure Logons to an SMB Share== | |||
Allows you to access Anonymous Linux SMB Shares | |||
In gpedit.msc, enable: | |||
<code>Computer Configuration\Administrative Templates\Network\Lanman Workstation\Enable insecure guest logons</code> | |||
==Add a static route== | |||
<code>route add -p <dest-network> MASK <dest-mask> <next-hop-ip> METRIC 0 IF <iface-num></code> | |||
=Other= | |||
==Text-to-speech== | |||
<code>powershell Add-Type -AssemblyName System.speech; $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer; $speak.Speak('I am groot')</code> | |||
=System Info= | |||
==Get PC's serial number== | |||
<code>wmic bios get serialnumber</code> | |||
<code>wmic csproduct get vendor,name,identifyingnumber</code> | |||
==Get Windows build number from an .iso file== | |||
<code>dism /get-wiminfo /wimfile:g:\sources\install.wim</code> | |||
Then, run it again with whichever index number you want to display: | |||
<code>dism /get-wiminfo /wimfile:g:\sources\install.wim /index:3</code> | |||
=Printers= | |||
==List printers== | |||
<code>wmic printer list brief</code> | |||
=Group Policy / AD= | |||
==List which GPO's are applied== | |||
<code>rsop.msc</code> (GUI version) | |||
<code>gpresult /r /scope computer</code> (CLI version) | |||
or save it to an html file with /h: | |||
<code>gpresult /h c:\gpresult.html</code> | |||
=Disk / Filesystem= | |||
==Format a disk== | |||
<code>get-disk</code> | |||
note the disk number, then: | |||
<code>clear-disk -number 1 -removedata -removeoem</code> (removes data partitions and OEM partitions) | |||
<code>new-partition -disknumber 1 -usemaximumsize</code> | |||
<code>get-partition -disknumber 1 | set-partition -newdriveletter D</code> | |||
=Certificates / SSL= | |||
==Convert x.509 (PKCS#12) to PFX== | |||
<code>openssl pkcs12 -export -out cert.pfx -inkey private.key -in cert.crt -certfile CACert.crt</code> (-certfile is not required) |
Revision as of 15:04, 19 November 2023
General
Updating
winget search Microsoft.PowerShell
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
net use \\path\to\shared\folder /user:<username>
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)