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

Comments

Popular posts from this blog

Adding Contact Selector Control to InfoPath form

Adding Validation to a Custom NewForm.aspx in SharePoint & Redirect

How to add to Sub-Sub Menu in SharePoint