There are several ways you can get the current directory where your PowerShell script or cmdlets are being executed. You can get this information using (Get-Location).path or ($pwd).path or for the latest PowerShell version using the $PSScriptRoot environment variable. Below is one example for your reference –
## Create a powershell script
echo "current path where script is being executed: $((Get-Location).path)"
echo "another example of current path: $(($pwd).path)"
echo "yet another example of current path: $((Get-Item .).FullName)"
echo "final one for latest version: $PSScriptRoot"
'@ > myscript.ps1
## Execute the PowerShell file