-
Notifications
You must be signed in to change notification settings - Fork 0
/
PowershellCommands.ps1
121 lines (68 loc) · 2.75 KB
/
PowershellCommands.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
Get-Volume
Get-PSDrive
Get-Volume -DriveLetter C
Get-Service bits, winrm, Spooler
Get-Command -name *disk -CommandType cmdlet, function
Get-Verb | more
Get-Command -Verb Mount
Get-Command -Noun disk*
Get-Command -Noun DiskImage
Get-Command -Noun disk* -Verb get
help Get-Disk -Examples
Get-Service -Name win* -Verbose
Get-Service win*
help Get-Service -Parameter requiredservices
Get-Process -Id $pid
help Get-Process -Parameter Id
Get-CimInstance #enter win32_logicaldisk
help Get-CimInstance -Parameter *name
Get-CimInstance Win32_OperatingSystem -Verbose -ComputerName localhost
Get-History 10 #shows the 10th last command that was run
Invoke-History 10 #runs the 10th last command that was run
Get-Module PSReadLine
Install-Module PSReadLine -Force
Get-PSReadLineOption
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -Colors @{InlinePrediction = "$([char]27)[4;38;5;189m"}
Get-Service -Name AppVClient
Get-Service win*
Get-service win*
Get-WinEvent -FilterHashtable @{Logname="Windows Powershell";Id=400} -MaxEvents 1 | Select-Object -ExpandProperty message
Get-WinEvent -ListLog * -ComputerName localhost -Credential company\administrator - message "Enter the admin credentials"
Get-WinEvent -LogName "Windows Powershell" -MaxEvents 10
Get-WinEvent -ListLog Microsoft-Windows-Powershell/Operational
Get-WinEvent Microsoft-Windows-Powershell/Operational -max 1 | Select-Object * | more
Get-WinEvent -FilterHashtable @{Logname = "Microsoft-Windows-Powershell/Operational"; ID=4100} -MaxEvents 5 | Select-Object -ExpandProperty message
Get-WinEvent -FilterHashtable @{Logname = "Microsoft-Windows-Powershell/Operational"; ID=4104} -MaxEvents 5 | Select-Object -ExpandProperty message
Show-EventLog #To open event viewer from powershell windows not powershell 7
#Windows powershell host
Write-Host "A is for apple" -ForegroundColor Yellow
Read-Host "Enter a service name"
Read-Host "Enter the passowrd" -AsSecureString
Get-CimInstance Win32_LogicalDisk -filter "deviceid='c:'" -Verbose
#you can also use the common errorvariable
Get-Service FooBarFun,winrm,BITS -ErrorVariable ev
$ev
$ev.exception | out-file c:\work\ev.txt
#$ev.exception > c:\work\ev.txt
#use >> to append to a file
get-content c:\work\ev.txt
#verbose
Get-CimInstance Win32_LogicalDisk -filter "deviceid='c:'" -Verbose 4>c:\work\verbose.txt
#another alias for get-content
Get-Content C:\work\verbose.txt
#to view environment variables
cd env:
dir
cmd.exe #to go back to the command prompt
cd function:
dir
cmd.exe
$a = Get-ChildItem function:help
$a.definition
$x = Get-ChildItem function:c:
$x.definition
Show-Command
help Get-Event -ShowWindow
Get-Help -Verbose about_*
Get-Service | Select-Object -Property Status, DisplayName | Where-Object { $_.Status -eq "Running" }