$psscriptroot empty when when script packaged as exe with merge-script. PoshProTools 4.1.8
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)
-
-
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
-
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.
-
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?
-
Ahh ok. That makes sense. I can fix this to work with cmdlet binding. That is likely the issue. Thanks.
-
- changed status to resolved
Fixes
#75→ <<cset 6ca663d19fe9>>
- Log in to comment
I am not seeing this behavior. Can you send me a $PSVersionTable?