Get relative path and name of the active Script in PowerShell
# Get complete file path (eg: D:\RootFolder\ActiveScript.ps1)
$0 = $MyInvocation.MyCommand.Definition
# Get current Directory file path (eg: D:\FolderA)
$dp0 = [System.IO.Path]::GetDirectoryName($0)
#To Get the root folder
$RootPath = $dp0 | split-path
# Get current Drive (eg: D:\)
$bits = Get-Item $dp0 | Split-Path -Parent
$0 = $MyInvocation.MyCommand.Definition
# Get current Directory file path (eg: D:\FolderA)
$dp0 = [System.IO.Path]::GetDirectoryName($0)
#To Get the root folder
$RootPath = $dp0 | split-path
# Get current Drive (eg: D:\)
$bits = Get-Item $dp0 | Split-Path -Parent
Comments
Post a Comment