๐งฉ PowerShell โ .NET Static Method Cheat Sheet
Common static methods and properties you can call with [Type]::Member.
๐งฎ [Math] โ Numeric Operations
| Example |
Result |
Description |
[Math]::Round(3.14159, 2) |
3.14 |
Round to 2 decimals |
[Math]::Ceiling(4.1) |
5 |
Round up |
[Math]::Floor(4.9) |
4 |
Round down |
[Math]::Pow(2, 10) |
1024 |
Power |
[Math]::Sqrt(49) |
7 |
Square root |
[Math]::Abs(-8) |
8 |
Absolute value |
[Math]::PI |
3.14159265358979 |
Constant |
[Math]::E |
2.71828182845905 |
Eulerโs number |
๐ [DateTime] โ Date & Time
| Example |
Result |
Description |
[DateTime]::Now |
Local time |
Current system time |
[DateTime]::UtcNow |
UTC time |
Coordinated Universal Time |
[DateTime]::Today |
Midnight |
Date without time |
[DateTime]::Parse("2025-10-31") |
DateTime |
Parse from text |
[DateTime]::IsLeapYear(2024) |
True |
Leap-year check |
[DateTime]::DaysInMonth(2025,2) |
28 |
Days in month |
๐ [IO.File] โ File Handling
| Example |
Result |
Description |
[IO.File]::ReadAllText("C:\Temp\log.txt") |
File content |
Read text |
[IO.File]::WriteAllText("C:\Temp\out.txt","Hello") |
โ |
Write text |
[IO.File]::AppendAllText("C:\Temp\out.txt","More") |
โ |
Append text |
[IO.File]::Exists("C:\Temp\out.txt") |
True/False |
Check file |
[IO.File]::Delete("C:\Temp\out.txt") |
โ |
Delete file |
๐ [IO.Directory] โ Directories
| Example |
Result |
Description |
[IO.Directory]::CreateDirectory("C:\Temp\Test") |
DirectoryInfo |
Create folder |
[IO.Directory]::Exists("C:\Temp\Test") |
Boolean |
Check folder |
[IO.Directory]::GetFiles("C:\Temp") |
Array of paths |
List files |
[IO.Directory]::Delete("C:\Temp\Test",$true) |
โ |
Delete recursively |
๐ [Environment] โ System Info
| Example |
Result |
Description |
[Environment]::MachineName |
Host name |
Computer name |
[Environment]::UserName |
Account |
Current user |
[Environment]::OSVersion |
OS info |
Windows version |
[Environment]::NewLine |
\n |
System newline |
[Environment]::GetFolderPath("Desktop") |
C:\Users\<User>\Desktop |
Special folder |
๐ค [String] โ String Utilities
| Example |
Result |
Description |
[String]::IsNullOrWhiteSpace(" ") |
True |
Check blank text |
[String]::Join(",",1,2,3) |
"1,2,3" |
Join values |
[String]::Concat("A","B","C") |
"ABC" |
Concatenate |
[String]::Compare("A","a",$true) |
0 |
Case-insensitive compare |
[String]::Empty |
"" |
Empty string constant |
๐ข [Convert] โ Type Conversions
| Example |
Result |
Description |
[Convert]::ToInt32("42") |
42 |
String โ Int |
[Convert]::ToString(255,16) |
"ff" |
Number โ Hex |
[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("Hi")) |
"SGk=" |
Encode |
[Convert]::FromBase64String("SGk=") |
Byte[] |
Decode |
๐งฉ [Guid] โ Identifiers
| Example |
Result |
Description |
[Guid]::NewGuid() |
xxxxxxxx-xxxx-... |
Create new GUID |
[Guid]::Empty |
{00000000-0000-0000-0000-000000000000} |
All-zero GUID |
โ๏ธ [Activator] โ Dynamic Instantiation
| Example |
Result |
Description |
[Activator]::CreateInstance([Type]) |
Object |
Same as New-Object |
[Activator]::CreateInstance([datetime],2025,1,1) |
DateTime |
Call constructor |
โป๏ธ [GC] โ Garbage Collector
| Example |
Description |
[GC]::Collect() |
Force garbage collection (rarely needed) |
๐ References