Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

$PSCommandPath is $null in parameters section and during debugging

$
0
0
Hello,

I'm trying to figure out how to find out where my script is located at the time of execution and from what I researched so far it seems to have been a problem with PS for sometime. I'm running PS 4.0 and inside ISE as well as inside PowerGui when I access $PSCommandPath variable in debug mode it always $null. The same variable works fine if I just use Write-Host $PSCommandPath.
What I want to do is to supply certain default values for parameters like below to inform script where to look for some resource files. It works with $pwd variable but not with $PSCommandPath. How do I reliably access variable informing me where is my script is located which I'm debugging or running?

[Parameter(Mandatory=$False)]
[string]$OutputFile = "$PSCommandPath\output_$(Get-Date -Format ('yyyy_dd_MM_hh_mm')).log",


Thanks,
G

Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>