Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Why $PSCommandPath is $null in ISE or PowerGUI

$
0
0

You can’t use certain automatic variables in your param block (such as $PSCommandPath, $MyInvocation, $PSCmdlet, etc); they don’t work the way you’d expect them to.

Instead, you can move that logic inside the script or function itself. For example:

param (
    [Parameter(Mandatory=$False)]
    [string]$OutputFile = $null
)

if (-not $OutputFile)
{
    $OutputFile = "$PSCommandPath\output_$(Get-Date -Format yyyy_dd_MM_hh_mm).log"
}

Viewing all articles
Browse latest Browse all 13067

Trending Articles