PowerShell - Return script root using $PSScriptRoot

by
Jeremy Canfield |
Updated: June 06 2023
| 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