0% found this document useful (0 votes)
18 views3 pages

PowerShell DotNet CheatSheet

This cheat sheet provides essential PowerShell commands for utilizing the .NET Framework across various categories including basic .NET usage, date and time manipulation, string encoding, networking, GUI interactions, audio and speech, file operations, performance diagnostics, and miscellaneous functions. It includes examples for creating objects, formatting dates, generating GUIDs, downloading files, and displaying message boxes. This resource serves as a quick reference for developers and system administrators working with PowerShell and .NET.

Uploaded by

fathialrabea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

PowerShell DotNet CheatSheet

This cheat sheet provides essential PowerShell commands for utilizing the .NET Framework across various categories including basic .NET usage, date and time manipulation, string encoding, networking, GUI interactions, audio and speech, file operations, performance diagnostics, and miscellaneous functions. It includes examples for creating objects, formatting dates, generating GUIDs, downloading files, and displaying message boxes. This resource serves as a quick reference for developers and system administrators working with PowerShell and .NET.

Uploaded by

fathialrabea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PowerShell + .

NET Framework Cheat Sheet

1. Basic .NET Usage


Check PowerShell version & loaded assemblies:
$PSVersionTable
[AppDomain]::[Link]()
Create an object from a .NET class:
$webClient = New-Object [Link]

2. Date & Time


Current date & time:
[DateTime]::Now
Custom format:
[DateTime]::[Link]("dddd, dd MMMM yyyy HH:mm:ss")
Add days:
(Get-Date).AddDays(10)

3. String & Encoding


Convert to Base64:
$text = "PowerShell"
[Convert]::ToBase64String([[Link]]::[Link]($text))
Decode Base64:
[[Link]]::[Link]([Convert]::FromBase64String("UG93ZXJTaGVsbA=="))
Uppercase:
"powershell".ToUpper()

4. Random & Security


Generate a GUID:
[guid]::NewGuid()
Generate a random password:
Add-Type -AssemblyName [Link]
[[Link]]::GeneratePassword(12,2)
Compute SHA256 Hash:
$text = "SecureData"
$bytes = [[Link]]::[Link]($text)
$hash = [[Link].SHA256]::Create().ComputeHash($bytes)
[BitConverter]::ToString($hash) -replace "-", ""

5. Networking
Download a file:
$url = "[Link]
$output = "C:\Temp\[Link]"
(New-Object [Link]).DownloadFile($url, $output)
Get external IP:
Invoke-RestMethod -Uri "[Link]
Ping:
$ping = New-Object [Link]
$[Link]("[Link]")

6. GUI & User Interaction


Message Box:
Add-Type -AssemblyName [Link]
[[Link]]::Show("Hello!", "PowerShell")
Open File Picker:
Add-Type -AssemblyName [Link]
$dialog = New-Object [Link]
$[Link]()
Save File Dialog:
Add-Type -AssemblyName [Link]
$save = New-Object [Link]
$[Link] = "Text Files (*.txt)|*.txt"
$[Link]()

7. Audio & Speech


Play sound:
Add-Type -AssemblyName [Link]
$sound = New-Object [Link] "C:\Windows\Media\[Link]"
$[Link]()
Text-to-Speech:
Add-Type -AssemblyName [Link]
$speak = New-Object [Link]
$[Link]("Hello from PowerShell!")

8. File Operations
Read text file:
[[Link]]::ReadAllText("C:\Temp\[Link]")
Write text file:
[[Link]]::WriteAllText("C:\Temp\[Link]", "Hello .NET")
Copy file:
[[Link]]::Copy("C:\Temp\[Link]","C:\Temp\file_copy.txt",$true)

9. Performance & Diagnostics


Stopwatch:
$timer = [[Link]]::StartNew()
Start-Sleep -Seconds 2
$[Link]()
$[Link]
Get processes:
[[Link]]::GetProcesses() | Select-Object ProcessName, Id

10. Miscellaneous Fun


Beep sound:
[console]::Beep(1000,500)
Progress bar:
for ($i=1; $i -le 100; $i++) {
Write-Progress -Activity "Loading" -Status "$i% Complete" -PercentComplete $i
Start-Sleep -Milliseconds 50
}
List fonts:
(Get-ChildItem "C:\Windows\Fonts").Name

You might also like