Updated cd-home.ps1

This commit is contained in:
Markus Fleschutz 2024-08-22 13:37:25 +02:00
parent 2e75436637
commit 65a0858f7a

View File

@ -4,7 +4,7 @@
.DESCRIPTION .DESCRIPTION
This PowerShell script changes the working directory to the user's home directory. This PowerShell script changes the working directory to the user's home directory.
.EXAMPLE .EXAMPLE
PS> ./cd-home PS> ./cd-home.ps1
📂C:\Users\Markus 📂C:\Users\Markus
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
@ -13,13 +13,11 @@
#> #>
try { try {
$Path = Resolve-Path -Path "~" $path = Resolve-Path "~"
if (Test-Path "$Path" -pathType container) { if (-not(Test-Path "$path" -pathType container)) { throw "Home folder at $path doesn't exist (yet)" }
Set-Location "$Path" Set-Location "$path"
"📂$Path" "📂$path"
exit 0 # success exit 0 # success
}
throw "User's home folder at 📂$Path doesn't exist (yet)"
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1