Skip to content

Instantly share code, notes, and snippets.

@adbertram
Created July 3, 2024 14:24
Show Gist options
  • Save adbertram/21a4c1e78f5d491b8e08f962924af56d to your computer and use it in GitHub Desktop.
Save adbertram/21a4c1e78f5d491b8e08f962924af56d to your computer and use it in GitHub Desktop.
$logEntries = @(
"2024-06-09",
"Error: Disk full",
404,
"2024-06-08",
"Error: Network unreachable",
500
)
foreach ($entry in $logEntries) {
switch ($entry) {
{ $_ -is [datetime] } { "Timestamp: $entry" }
{ $_ -is [int] } { "Error code: $entry" }
{ $_ -is [string] -and $_ -match "^Error:" } { "Error message: $entry" }
default { "Unknown type: $entry" }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment