Home > other >  Check if current script running directory is a defined folder
Check if current script running directory is a defined folder

Time:01-01

I got to know that $PSScriptRoot returns the current directory where the script is running. However, using it with an if statement does not work even though the script is running in the same directory as defined.

if ($PSScriptRoot -eq "~/.folderwithdotbeforeit/somefolder") {
Write-Host "True"
}

CodePudding user response:

$PSScriptRoot is a string, not a Path, so you would need to compare it to a string containing the absolute path you are expecting. In your case, replace ~ by the absolute path of your home directory.

  • Related