# Define function
function Windows.Switch-ToChildFolder {
param(
$Path = $PWD
)
pushd $pwd
$dir = gci $path | Where {$_.PSIsContainer} | select fullname;
if($dir.length -gt 0) {
Write-Output "There are $($dir.length) children folders.";
for($i = 1; $i -le $dir.length; $i++) {
Write-Output "$($i): $($dir[($i-1)].fullname)";
}
$response = Read-Host "Type the number for the folder you want to select";
cd $dir[$($response-1)].fullname | Out-Null;
} else {
Write-Output "The current
directory has no children";
}
} # end function Windows.Switch-ToChildFolder
# Set alias
Set-Alias -Name w.stcf -Value "Windows.Switch-ToChildFolder"
Set-Alias -Name Down -Value "Windows.Switch-ToChildFolder"
Set-Alias -Name d -Value "Windows.Switch-ToChildFolder"The really cool thing here is that when you run the cmdlet it gives you a numbered list of folders into which you can go simply by typing the folder number. For example, using down to navigate the $PSHOME directory gives me this:
}
} # end function Windows.Switch-ToChildFolder
# Set alias
Set-Alias -Name w.stcf -Value "Windows.Switch-ToChildFolder"
Set-Alias -Name Down -Value "Windows.Switch-ToChildFolder"
Set-Alias -Name d -Value "Windows.Switch-ToChildFolder"The really cool thing here is that when you run the cmdlet it gives you a numbered list of folders into which you can go simply by typing the folder number. For example, using down to navigate the $PSHOME directory gives me this:
PS C:> down $pshome
There are 4 children folders.
1: C:WindowsSystem32WindowsPowerShellv1.0en-US
2: C:WindowsSystem32WindowsPowerShellv1.0Examples
3: C:WindowsSystem32WindowsPowerShellv1.0Modules
4: C:WindowsSystem32WindowsPowerShellv1.0 estmodules
Type the number for the folder you want to select: 4
C:WindowsSystem32WindowsPowerShellv1.0 estmodules
PS C:WindowsSystem32WindowsPowerShellv1.0 estmodules>