Bootstrap FreeKB - PowerShell - Return script root using $PSScriptRoot
PowerShell - Return script root using $PSScriptRoot

Updated:   |  PowerShell articles

The $PSScriptRoot variable can be used to return the base directory for your PowerShell script. For example, let's say you have the following in C:\Users\johndoe\scripts\example.ps1.

Write-Host "PSScriptRoot = $PSScriptRoot"

 

Should return something like this.

PSScriptRoot = C:\Users\johndoe\scripts

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter f50eef in the box below so that we can be sure you are a human.