2016-07-13 16 views
1

Pfad Beispiel: 'C: \ ordnerA \ ordnerB \ FolderC \ script.ps1'PowerShell 2 Ordner aus Pfad abrufen?

Mit Split-Path, ich bin in der Lage 'FolderC' zu bekommen, aber wie würde ich 'ordnerB'?

Split-Path (Split-Path $MyInvocation.MyCommand.Definition -Parent) -Leaf 

Dies gibt folderC zurück.

Antwort

1

Nun könnte man einfach eine andere hinzufügen Split-Path

Split-Path (Split-Path (Split-Path $MyInvocation.MyCommand.Definition -Parent) -Parent) -Leaf 

als Pipeline würde es so aussehen wie

Split-Path $MyInvocation.MyCommand.Definition -Parent | 
    Split-Path -Parent | 
    Split-Path -Leaf 
Verwandte Themen