question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent folder behavior in Powershell

See original GitHub issue

One 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Francisco-Gaminocommented, Aug 21, 2019

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:

using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."

write-output "PSScriptRoot: $PSScriptRoot"
write-output "Directory: $($TriggerMetadata.FunctionDirectory)"

# more code ...

Output: image

0reactions
Francisco-Gaminocommented, Sep 24, 2019

Hello @mattsmall1972, thank you for reporting this. I have opened an issue to track this: https://github.com/Azure/azure-functions-host/issues/4969

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found