Inconsistent folder behavior in Powershell
See original GitHub issueOne of my colleagues is getting different path when using
Set-Location (split-path -parent $MyInvocation.MyCommand.Definition)
In my case I get the folder where my function is located (run.ps1) but a newer machine is getting the Functions folder
Did some search and found these variables in the wiki https://github.com/Azure/azure-functions-host/wiki/Retrieving-information-about-the-currently-running-function
but running with the vars got me null values on local development
Set-Location (join-path $EXECUTION_CONTEXT_FUNCTIONDIRECTORY $EXECUTION_CONTEXT_FUNCTIONNAME)
Shouldn’t these env var behave the same way both in Azure as in local windows laptop?
Investigative information
- Function App version (1.0 or 2.0): 2.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Copy-Item inconsistent behavior? - powershell
In the first case the destination folder C:\temp\B\A doesn't exist, so Copy-Item creates the (missing) destination folder and copies the ...
Read more >Powershell Copy-Item recursively but don't include folder ...
Your command is telling PowerShell to copy the folder itself, with all its contents, to the destination folder. To copy only the contents...
Read more >Win 11 File Explorer Preview Pane Inconsistent Behavior
File Explorer Preview pane works fine for MS Office documents, PDF in all folders and subfolders. But not for the bmp, png files...
Read more >Differences between Windows PowerShell 5.1 and ...
The most notable differences are in the availability and behavior of PowerShell cmdlets between Windows and non-Windows platforms and the ...
Read more >Manipulating Items Directly - PowerShell
To move a file or folder, use the Move-Item cmdlet. For example, the following command moves the New.Directory directory from the C:\temp ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello @canoas, here are a couple of ways to get the folder location of your executing function:
If you take a look at https://github.com/Azure/azure-functions-host/wiki/Retrieving-information-about-the-currently-running-function, you can use
FunctionDirectory
, e.g.,write-output "Directory: $($TriggerMetadata.FunctionDirectory)"
. Alternatively, you can the PowerShell built-in variable$PSScriptRoot
. Both of them should point you to the same location.Sample code:
Output:
Hello @mattsmall1972, thank you for reporting this. I have opened an issue to track this: https://github.com/Azure/azure-functions-host/issues/4969