PSScriptRoot
suggest changeGet-ChildItem -Path $PSScriptRoot
This example retrieves the list of child items (directories and files) from the folder where the script file resides.
$PSScriptRoot is $null outside a script file, including at the interactive prompt. Inside a script, it is the fully qualified filesystem path of the directory that contains the script file.
In Windows PowerShell 2.0, this variable is valid only in script modules (.psm1). Beginning in Windows PowerShell 3.0, and in PowerShell 6 and later, it is valid in all scripts.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents