Useful powershell commands (and cmd) Flashcards

must learn these!

1
Q

How to convert from base64 powershell?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Show system information

A

systeminfo

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

List all running processes

A

tasklist

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Kill a process by name

A

taskkill /IM [process_name] /F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Kill a process by PID

A

taskkill /PID [pid] /F

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Clear the command prompt screen

A

cls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

List files in a directory

A

dir

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Change directory

A

cd [directory]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Create a new directory

A

mkdir [directory]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Remove a directory

A

rmdir /S /Q [directory]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Copy a file

A

copy [source] [destination]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Move or rename a file

A

move [source] [destination]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Delete a file (cmd)

A

del [file_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Show IP configuration

A

ipconfig /all

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Release IP address

A

ipconfig /release

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Renew IP address

A

ipconfig /renew

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Flush DNS cache

A

ipconfig /flushdns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Display active network connections

A

netstat -an

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Display listening ports

A

netstat -an | find “LISTEN”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Ping a host

A

ping [hostname_or_ip]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Trace route to a host

A

tracert [hostname_or_ip]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Check open ports on a remote host (cmd)

A

telnet [hostname_or_ip] [port]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Shutdown the computer

A

shutdown /s /t 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Restart the computer

A

shutdown /r /t 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Log off current user

A

shutdown /l

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Check disk usage

A

chkdsk

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Check and repair disk errors

A

chkdsk /f

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Show available disk space

A

wmic logicaldisk get size,freespace,caption

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

List installed programs

A

wmic product get name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Find specific installed program

A

wmic product where “name like ‘%[program_name]%’” get name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Create a new user

A

net user [username] [password] /add

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Delete a user

A

net user [username] /delete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Add user to a group

A

net localgroup [groupname] [username] /add

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Remove user from a group

A

net localgroup [groupname]
[username] /delete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

List all users

A

net user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

List all groups

A

net localgroup

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Enable remote desktop

A

reg add “HKLM\System\CurrentControlSet\Control\Terminal Server” /v fDenyTSConnections /t REG_DWORD /d 0 /f

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

Disable remote desktop

A

reg add “HKLM\System\CurrentControlSet\Control\Terminal Server” /v fDenyTSConnections /t REG_DWORD /d 1 /f

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Start a service (cmd)

A

net start [service_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

Stop a service

A

net stop [service_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

List all services

A

sc query

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

Check service status (cmd)

A

sc query [service_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Enable a service

A

sc config [service_name] start= auto

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

Disable a service (cmd)

A

sc config [service_name] start= disabled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

List all environment variables

A

set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

Set an environment variable

A

setx [variable_name] [value] /M

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

Delete an environment variable

A

setx [variable_name] “” /M

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

Get current date (cmd)

A

echo %DATE%

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

Get current time

A

echo %TIME%

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

Find a string in a file

A

findstr “pattern” [file_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

Create a compressed zip file (powershell)

A

Compress-Archive -Path [file_name] -DestinationPath [output.zip]

52
Q

Extract a zip file

A

Expand-Archive -Path [input.zip] -DestinationPath [directory]

53
Q

Get running processes (PowerShell)

A

Get-Process

54
Q

Kill a process (PowerShell)

A

Stop-Process -Name [process_name] -Force

55
Q

Get system uptime (PowerShell)

A

(get-date) - (gcim Win32_OperatingSystem).LastBootUpTime

56
Q

Get system information (PowerShell)

A

Get-ComputerInfo

57
Q

List installed software (PowerShell)

A

Get-WmiObject -Query “SELECT * FROM Win32_Product”

58
Q

Check Windows version (PowerShell)

A

“[System.Environment]::OSVersion”

59
Q

Restart a service (PowerShell)

A

Restart-Service -Name [service_name]

60
Q

List network adapters (PowerShell)

A

Get-NetAdapter

61
Q

Disable network adapter (PowerShell)

A

Disable-NetAdapter -Name “[adapter_name]”

62
Q

Enable network adapter (PowerShell)

A

Enable-NetAdapter -Name “[adapter_name]”

63
Q

Get IP configuration (PowerShell)

A

Get-NetIPConfiguration

64
Q

Get firewall rules (PowerShell)

A

Get-NetFirewallRule

65
Q

Enable firewall rule (PowerShell)

A

Enable-NetFirewallRule -DisplayName “[rule_name]”

66
Q

Disable firewall rule (PowerShell)

A

Disable-NetFirewallRule -DisplayName “[rule_name]”

67
Q

Check open ports (PowerShell)

A

Test-NetConnection -ComputerName [hostname_or_ip] -Port [port]

68
Q

Ping a host (PowerShell)

A

Test-Connection -ComputerName <hostname_or_ip

69
Q

List active TCP connections (PowerShell)

A

Get-NetTCPConnection

70
Q

Restart computer (PowerShell)

A

Restart-Computer -Force

71
Q

Shutdown computer (PowerShell)

A

Stop-Computer -Force

72
Q

Get available storage (PowerShell)

A

Get-PSDrive -PSProvider FileSystem

73
Q

Check disk health (PowerShell)

A

Get-PhysicalDisk

74
Q

Format a disk (PowerShell)

A

Format-Volume -DriveLetter [drive_letter] -FileSystem NTFS -NewFileSystemLabel “NewLabel”

75
Q

List running services (PowerShell)

A

Get-Service

76
Q

Start a service (PowerShell)

A

Start-Service -Name [service_name]

77
Q

Stop a service (PowerShell)

A

Stop-Service -Name [service_name]

78
Q

Set execution policy (PowerShell)

A

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

79
Q

Run a script as administrator (PowerShell)

A

Start-Process PowerShell -Verb RunAs -ArgumentList “-File [script.ps1]”

80
Q

List scheduled tasks (PowerShell)

A

Get-ScheduledTask

81
Q

Get system logs (PowerShell)

A

Get-EventLog -LogName System -Newest 10

82
Q

Export event logs to a file (PowerShell)

A

wevtutil epl System C:\Logs\system.evtx /ow:true

83
Q

Get information about an AD Domain

A

Get-ADDomain

84
Q

See what groups you’re in

A

whoami /groups

85
Q

How to download http powershell? 1

A

(New-Object Net.WebClient).DownloadFile(‘[Target File URL]’,’[Output File Name]’)

86
Q

Fileless download execution powershell? 1

A

(New-Object Net.WebClient).DownloadString(‘[url]’) | IEX

87
Q

How to download http powershell? 2

A

Invoke-WebRequest [url] -OutFile [out_file]

88
Q

Fileless download powershell? 2

A

Invoke-WebRequest [url] -UseBasicParsing | IEX

89
Q

https download untrusted certificate bypass powershell?

90
Q

http upload powershell? 1

A

IEX(New-Object Net.WebClient).DownloadString(‘https://raw.githubusercontent.com/juliourena/plaintext/master/Powershell/PSUpload.ps1’) && Invoke-FileUpload -Uri [url] -File [file]

91
Q

http upload powershell? 2

A

b64 = [System.convert]::ToBase64String((Get-Content -Path ‘[file]’ -Encoding Byte)) && Invoke-WebRequest -Uri [url] -Method POST -Body $b64

92
Q

How to list the contents of a share? 1

A

dir \\[ip]\share

93
Q

How to copy a file from a share?

A

copy <file> \\[host]\[file]</file>

94
Q

Map smb share to drive?

A

net use n: \[ip][share]

95
Q

Map smb share to drive with auth?

A

net use n: \[ip][share] /user:[username] [password]

96
Q

List total number of files in a share after mapped?

A

dir [drive]: /a-d /s /b | find /c “:"

97
Q

How to search for file names with dir?

A

dir n:*[name]* /s /b

98
Q

How to map smb share to drive powershell?

A

New-PSDrive -Name “N” -Root “\[hostname][share]” -PSProvider “FileSystem”

99
Q

How to create PSCredential object?

A

$secpassword = ConvertTo-SecureString [pass] -AsPlainText -Force &&
$cred = New-Object System.Management.Automation.PSCredential [user] $secpassword

100
Q

How to count the number of files in a share powershell?

A

cd [drive]: && (Get-ChildItem -File -Recurse | Measure-Object).Count

101
Q

How to start a powershell remote session?

A

$Session = New-PSSession -ComputerName [hostname]

102
Q

How to upload a file to a remote powershell session?

A

Copy-Item -Path [file] -ToSession $Session -Destination [out_file]

103
Q

How to download a file from a remote powershell session?

A

Copy-Item -Path [file] -Destination [file] -FromSession $Session

104
Q

How to access an rdp mounted filesystem?

A

dir \tsclient\

105
Q

How to encrypt a file powershell?

A

Invoke-AESEncryption -Mode Encrypt -Key [encryption_key] -Path [outfile]

106
Q

How to POST a file with certreq.exe?

A

certreq.exe -Post -config [url]

107
Q

How to download http with BITSadmin powershell?

A

Import-Module bitstransfer; Start-BitsTransfer -Source [url] -Destination [path]

108
Q

How to download with certutil http?

A

certutil.exe -verifyctl -split -f http://<remote>:<remote>/<remote></remote></remote></remote>

109
Q

How to download http with GfxDownloadWrapper.exe?

A

GfxDownloadWrapper.exe [url] [path]

110
Q

How to open diskmanagement?

A

win + r “diskmgmt.msc”

111
Q

How to connect to a remote MSSQL database via commandline?

A

sqsh -S [ip] -U [user] -P [pass]

112
Q

How to connect to mysql database via commandline?

A

mysql.exe -u [username] -p[password]-h [ip]

113
Q

How to find an AD user by name powershell?

A

Get-ADUser -Filter “Name -eq [name]” -Properties *

114
Q

How to remove an AD user powershell?

A

Remove-ADUser -Identity [SamAccountName]

115
Q

How to add an AD User powershell?

A

Add-ADUser (-FullName …, -SamAccountName…, -DisplayName…, -Password.., ect.)

116
Q

How to unlock an AD account powershell?

A

Unlock-ADAccount [SamAccountName]

117
Q

How to reset the password for an AD account powershell?

A

Set-ADAccountPassword -Identity [SamAccountName] -Reset -NewPassword (ConvertTo-SecureString -AsPlainText [password] -Force)

118
Q

How to set an AD Account to create a new password at next logon powershell?

A

Set-ADUser -Identity [SamAccountName] -ChangePasswordAtLogon $true

119
Q

How to copy a GPO powershell?

A

Copy-GPO -SourceName [GPO-to-copy] -TargetName [copied GPO name]

120
Q

How to link a GPO to an OU powershell?

A

New-GPLink -Name [GPO name] -Target [OU name] -LinkEnabled Yes

121
Q

What command is used to domain-join a local computer powershell?

A

Add-Computer -DomainName [domain name] -Credential INLANEFREIGHT[admin uname] -Restart

122
Q

What command is used to domain join a remote computer powershell?

A

Add-Computer -ComputerName [hostname] -LocalCredential [local admin uname] -DomainName [domain name] -Credential [domain admin uname] -Restart

123
Q

How to find the OU membership of a computer powershell?

A

Get-ADComputer -Identity [hostname] -Properties * | select CN,CanonicalName,IPv4Address

124
Q

How to check if a computer is domain joined?

A

systeminfo | findstr /B “Domain”
(or check in settings)

125
Q

Which command output details the required and available security properties of a computer?

A

systeminfo