{"version":"1.0","type":"rich","title":"Use different techniques to determine a PowerShell script's directory: try `$PSScriptRoot`, `$MyInvocation.MyCommand.Path`, `$ExecutionContext.SessionState.Module.Path` and `$PWD`.","description":"This example demonstrates a PowerShell script that attempts to locate its own directory using four different techniques in a fallback sequence: `$PSScriptRoot`, `$MyInvocation.MyCommand.Path`, `$ExecutionContext.SessionState.Module.Path`, and finally `$PWD`. The code defines a function `Get-ScriptPath` that checks each variable in order, using `Split-Path` to extract the parent directory when necessary. It shows the logic for handling environments where certain automatic variables may be unavailable, such as when the script is invoked from a module or interactive session. The example relies on PowerShell’s built-in `Get-Variable` cmdlet and conditional checks to progressively resolve the path.","provider_name":"VizHub AI Studio","provider_url":"https://next.vizhub.com","html":"<iframe src=\"https://next.vizhub.com/viz/gist-c3a7d2f1cc2e1a73c62d5d95a5969d84?mode=embed\" width=\"960\" height=\"500\" scrolling=\"no\" frameborder=\"1\"></iframe>","width":960,"height":500,"cache_age":3600}