So if I have a directory stored in a variable, say:
$scriptPath = (Get-ScriptDirectory);
Now I would like to find the directory two parent levels up.
I need a nice way of doing:
$parentPath = Split-Path -parent $scriptPath
$rootPath = Split-Path -parent $parentPath
Can I get to the rootPath in one line of code?
Version for a directory
get-itemis your friendly helping hand here.If you Want the string only
Version for a file
If
$scriptPathpoints to a file then you have to callDirectoryproperty on it first, so the call would look like thisRemarks
This will only work if
$scriptPathexists. Otherwise you have to useSplit-Pathcmdlet.