Skip to content

Latest commit

 

History

History
65 lines (53 loc) · 1.37 KB

File metadata and controls

65 lines (53 loc) · 1.37 KB

Script: cd-users.ps1

This PowerShell script sets the current working directory to the users directory.

Parameters

PS> ./cd-users.ps1 [<CommonParameters>]

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

Example

PS> ./cd-users.ps1
📂C:\Users with 4 folders entered.

Notes

Author: Markus Fleschutz | License: CC0

Related Links

https://github.com/fleschutz/PowerShell

Script Content

<#
.SYNOPSIS
	Sets the working dir to the users directory
.DESCRIPTION
	This PowerShell script sets the current working directory to the users directory.
.EXAMPLE
	PS> ./cd-users.ps1
	📂C:\Users with 4 folders entered.
.LINK
	https://github.com/fleschutz/PowerShell
.NOTES
	Author: Markus Fleschutz | License: CC0
#>

#requires -version 5.1

try {
	$path = Resolve-Path "~/.."
	if (-not(Test-Path "$path" -pathType container)) { throw "No users directory at: $path" }

	Set-Location "$path"
	$folders = Get-ChildItem $path -attributes Directory
	"📂$path with $($folders.Count) folders entered."
	exit 0 # success
} catch {
	"⚠️ ERROR: $($Error[0])"
	exit 1
}

(page generated by convert-ps2md.ps1 as of 08/07/2025 16:01:02)