-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.ps1
56 lines (41 loc) · 1.9 KB
/
example.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
# Get-Verb, Get-Command, Get-Help, Get-Member
#
# Gives all the information about powershell installation
$PSVersionTable
# PSVersionTable is a like a HashMap
# TypeName: System.Management.Automation.PSVersionHashTable
$PSVersionTable.GetType()
$PSVersionTable.Keys
# We are iterating over each key inside the HashTable and getting the key and value in that key
$PSVersionTable.Keys | ForEach-Object {
$_, $PSVersionTable.Item($_)
}
# Display Major, minor and patch version of the powershell
$PSVersionTable.PSVersion | Select-Object Major, Minor, Patch | Format-List
# Get all the command-lets or cmdlets available on the Powershell
Get-Verb | ForEach-Object {
$_.Verb
}
# Get more information or go directly to the command let
Get-Command -Name Add-Content
Get-Command -Verb Add
Get-Command -Noun Member
Get-Command -Verb Get -Noun Member
Get-Command -Verb Get -Noun Win*
# To get Help about command lets
Get-Help -Name Add-Content
# Both commands are the same
$PSVersionTable | Get-Member -MemberType Property
Get-Member -InputObject $PSVersionTable -MemberType Property
# Stuff about files
Get-FileHash -Path .\example.ps1 -Algorithm SHA256 | Format-List
Get-FileHash -Path .\example.ps1 -Algorithm SHA384 | Format-Table
Get-FileHash -Path .\example.ps1 -Algorithm SHA384 | Format-Wide Hash
Get-Process -Name 'teams' | Sort-Object -Descending -Property CPU
Get-Process -Name 'teams' | Sort-Object -Descending -Property CPU, WS
Get-Process -Name 'teams' | Sort-Object -Property @{ Expression = "CPU"; Descending = $True }, @{ Expression = "WS"; Descending = $False }
Get-Process -Name 'teams' | Where-Object WS -gt 90 | Sort-Object -Descending -Property CPU | Select-Object -First 1
# To update help documentation, use: Update-Help -UICulture en-US
# To create a new file use: 'New-Item filename.ps1' and after that use 'code filename.ps1' to open it in visual studio code
Write-Output "Hello world!".ToLower()
"Hello world"