Skip to content

Commit ba65ee0

Browse files
committed
Add cd-windows.ps1
1 parent b26ac88 commit ba65ee0

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Scripts/cd-windows.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<#
2+
.SYNOPSIS
3+
Sets the working directory to the Windows directory
4+
.DESCRIPTION
5+
This script changes the working directory to the Windows directory.
6+
.EXAMPLE
7+
PS> ./cd-windows
8+
📂C:\Windows
9+
.LINK
10+
https://github.com/fleschutz/PowerShell
11+
.NOTES
12+
Author: Markus Fleschutz · License: CC0
13+
#>
14+
15+
try {
16+
$TargetDir = resolve-path "$env:WINDIR"
17+
if (-not(test-path "$TargetDir" -pathType container)) {
18+
throw "Windows directory at 📂$TargetDir doesn't exist"
19+
}
20+
set-location "$TargetDir"
21+
"📂$TargetDir"
22+
exit 0 # success
23+
} catch {
24+
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
25+
exit 1
26+
}

0 commit comments

Comments
 (0)