From 82abfcf4628621fb9d481820ca06bda8ca39b792 Mon Sep 17 00:00:00 2001 From: Benjamin Aparicio Hernandez Date: Thu, 12 Oct 2023 16:19:08 -0600 Subject: [PATCH] Update PowerShell.md Fixed some operator mistakes. Expand aliases to full cmdlets. Remove semicolons at EOL. --- cheat-sheet/Windows/PowerShell.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cheat-sheet/Windows/PowerShell.md b/cheat-sheet/Windows/PowerShell.md index 7481e9e9e..a8fd5f40a 100644 --- a/cheat-sheet/Windows/PowerShell.md +++ b/cheat-sheet/Windows/PowerShell.md @@ -1,7 +1,7 @@ ## Condition Examples - if ((-not [string]::IsNullOrEmpty($string))) - if (($nr > 5) -and ($string eq '')) + if ((-not [string]::IsNullOrEmpty($string))) { ... } + if (($nr -gt 5) -and ($string -eq '')) { ... } ## Control Flow @@ -15,9 +15,9 @@ ### Exceptions try { - throw "My exception"; + throw "My exception" } catch { - Write-Output "Caught exception!"; + Write-Output "Caught exception!" } ## Functions @@ -35,9 +35,9 @@ Fetching - $tmp = $env:SOME_ENV_VAR; + $tmp = $env:SOME_ENV_VAR - $env:Path = [Environment]::GetEnvironmentVariable('Path',[System.EnvironmentVariableTarget]::Machine); + $env:Path = [Environment]::GetEnvironmentVariable('Path',[System.EnvironmentVariableTarget]::Machine) Setting env var on global level @@ -70,8 +70,8 @@ Removing files/directories ## Download by URL - iwr -useb http://example.com/somefile - iwr -useb http://example.com/someexe | iex # Download and execute it + Invoke-WebRequest -useb http://example.com/somefile + Invoke-WebRequest -useb http://example.com/someexe | Invoke-Expression # Download and execute it ## Check PowerShell Version