$psscriptroot empty when when script packaged as exe with merge-script. PoshProTools 4.1.8

Issue #75 resolved
Emrys MacInally created an issue

just tried it with the newest version and it still doesn't work.

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   4.1.8      PowerShellProTools                  {ConvertTo-CSharp, ConvertTo-PowerShell, Get-PoshProToolsLicense, Install-PoshProToolsLicense...}

script I'm testing with:

$var = $PSScriptRoot
Write-Output "var =  $var"

output if when running as script:

PS C:\GIT> c:\GIT\Untitled-1.ps1

                               var =  C:\GIT

convert to exe with merge script:

Merge-Script -Script .\Untitled-1.ps1 -Package -OutputPath .\

output of exe: "var= "

I'm getting something wrong?

Comments (6)

  1. Adam Driscoll

    I am not seeing this behavior. Can you send me a $PSVersionTable?

    PS C:\Users\adamr> $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      5.1.17134.590
    PSEdition                      Desktop
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    BuildVersion                   10.0.17134.590
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    PS C:\Users\adamr> install-module -Name PowerShellProTools -Scope CurrentUser -Force
    PS C:\Users\adamr> cd .\Desktop\
    PS C:\Users\adamr\Desktop> Import-Module PowerShellProTools
    PS C:\Users\adamr\Desktop> Get-Module
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
    Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
    Script     1.1.7.2    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...
    Script     1.6.7      PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCap...
    Manifest   4.1.8      PowerShellProTools                  {ConvertTo-CSharp, ConvertTo-PowerShell, Get-PoshProToolsL...
    Script     1.2        PSReadline                          {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PS...
    
    PS C:\Users\adamr\Desktop> Merge-Script -Script .\script.ps1 -Package -OutputPath .\out\
    PS C:\Users\adamr\Desktop> .\out\script.exe
    Test = C:\Users\adamr\Desktop\out
    
  2. Emrys MacInally reporter
    #!
    
    PS C:\WINDOWS\system32> $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      5.1.17134.590
    PSEdition                      Desktop
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    BuildVersion                   10.0.17134.590
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    
  3. Emrys MacInally reporter

    Removed all versions of powershell pro tools and reinstalled version 4.1.8. know my test package returns $PSSCRIPTROOT as expected.
    Repackaged my script with Version 4.1.8 and now i receive following error:

    At line:2 char:8
    + param (, $PoshToolsRoot)
    +        ~
    Missing ')' in function parameter list.
    At line:1 char:3
    + & { [CmdletBinding()]
    +   ~
    Missing closing '}' in statement block or type definition.
    At line:2 char:24
    + param (, $PoshToolsRoot)
    +                        ~
    Unexpected token ')' in expression or statement.
    At line:608 char:2
    +  } -PoshToolsRoot C:\GIT\monitoring
    +  ~
    Unexpected token '}' in expression or statement.
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : MissingEndParenthesisInFunctionParameterList
    

    Reinstalling 1.12.0 and repackaging gets my script running again.

  4. Emrys MacInally reporter

    my guess the problem has to do with the beginning of my script. my script consists of multiple ps1 files in functions which are do sourced when called for the first time. all dot sourced files are merged into one file and then packed. the starting point is this script:

    [CmdletBinding()]
    param ()
    . .\Start-MMMonitoring.ps1
    Start-MMMonitoring @PSBoundParameters
    Stop-Process -Id $pid -Force
    

    if i remove

    [CmdletBinding()]
    param ()
    

    the packaged script will run fine, but i lose the ability to start the exe with -verbose parameter. is the a other way a could pass in parameters like in 1.12.0?

  5. Adam Driscoll

    Ahh ok. That makes sense. I can fix this to work with cmdlet binding. That is likely the issue. Thanks.

  6. Log in to comment