Skip to content

Commit

Permalink
[PowerShell] Add some basic commands
Browse files Browse the repository at this point in the history
  • Loading branch information
komidawi committed Dec 5, 2024
1 parent ada06f0 commit 30f53da
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions _posts/learning/shell/2024-12-05-PowerShell.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ categories: [ shell ]
tags: [ windows, powershell ] # TAG names should always be lowercase
---

## Basics

**Set Output**

`Out-File` (bash `>`)
Expand Down Expand Up @@ -35,9 +37,20 @@ Copy-Item `
-PassThru
```

**Enable debugging**
**Remove file**

`Remove-Item` (bash `rm`)

```powershell
Remove-Item ./file.txt
```

`Set-PSDebug -Trace 1`
**String interpolation**

```powershell
$VERSION = "2.1.1-SNAPSHOT"
$jarFile = "myapp-$VERSION.jar"
```

**Download File**

Expand All @@ -55,6 +68,33 @@ Alternative
iwr localhost:8080/archive.zip -o logs.zip
```

## Various

**Check if file exists**

```powershell
if (Test-Path -Path $TARGET_FILE -PathType Leaf)
{
# ...
}
```

## Shell behavior config

**Enable debugging**

`Set-PSDebug -Trace 1` (bash `set -x`)

**Stop execution on first error**

`$ErrorActionPreference` (bash `set -e`)

```powershell
$ErrorActionPreference = "Stop"
```

## PowerShell Profile

**Get location of PowerShell Profile**

- Note that this location actually may not contain any file - in such case it will be needed to create it manually
Expand Down

0 comments on commit 30f53da

Please sign in to comment.