Running into what appears to be a bug in PowerShell ISE v3 (or at least a different behavior), and wondering if someone could confirm and possibly shed some light on why?
Assume a script named Test.PS1 contains the following simple code:
Param ([string]$CurrentPath = (Split-Path ((Get-Variable MyInvocation -Scope 0).Value).MyCommand.Path)) Write-Host $CurrentPath
If I run that script $CurrentPath contains the path that the script exists in as expected. However, if the script contains [CmdletBinding()] at the top like this:
[CmdletBinding()] Param ([string]$CurrentPath = (Split-Path ((Get-Variable MyInvocation -Scope 0).Value).MyCommand.Path)) Write-Host $CurrentPath
PowerShell ISE v3 returns an error "Split-Path : Cannot bind argument to parameter 'Path' because it is null." similar to if the script wasn't saved. However if the script is executed from the CLI it works fine, and it works fine in ISE v2.
Is anyone able to repeat this, or possibly shed some light on why it might be occuring? We're in the process of moving some scripts over to a 2012 server, and this came up.
Thanks!