Product, version and build: Powershell Studio 2015 V. 4.2.96
32 or 64 bit version of product: 64bit
Operating system: Windows 8.1 Enterprise
32 or 64 bit OS: 64bit
I made a big script with some language specifict output. if I run the script in Powershell Studio, all the language specific variables show the correct values. If I package it as .exe those are completely missing. The language files are located like this:
Project
----Globals.ps1
----Mainform.ps1
----de-DE
--------Language.psd1
----en-EN
--------Language.psd1
How can I check if the .exe includes my psd1 files? If it does not include it, how can I include those folders in the .exe?
Edit: If you want to directly check my script, it is on GITHub. I can PM you the link
Powershell Studio - Include Language Files (.psd1) in exe
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- renato.bacchi
- Posts: 8
- Last visit: Tue Oct 30, 2018 1:46 am
Re: Powershell Studio - Include Language Files (.psd1) in exe
It does not embed them and you will have to include any dependent language files alongside the executable. I recommend creating a MSI so that you can package all the dependent files with the executable.
You will also have to test the language files with the executable because it runs the script from memory and not a specific script file. I'm not sure if this will cause a problem.
David
You will also have to test the language files with the executable because it runs the script from memory and not a specific script file. I'm not sure if this will cause a problem.
David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- renato.bacchi
- Posts: 8
- Last visit: Tue Oct 30, 2018 1:46 am
Re: Powershell Studio - Include Language Files (.psd1) in exe
How do I multiple languages then?
If i put my .exe in the folder with one language.psd1 the values are correct.
But I want to use the integrated localization function. ATM I would have to make the user to put the exe in the correct folder, which is not really what i want.
It would be cool if it worked like this:
Exe
de-DE
----Language.psd1
en-EN
----Language.psd1
I don't have a problem with installing 2 more folders, but it has to work for all languages
If i put my .exe in the folder with one language.psd1 the values are correct.
But I want to use the integrated localization function. ATM I would have to make the user to put the exe in the correct folder, which is not really what i want.
It would be cool if it worked like this:
Exe
de-DE
----Language.psd1
en-EN
----Language.psd1
I don't have a problem with installing 2 more folders, but it has to work for all languages
Re: Powershell Studio - Include Language Files (.psd1) in exe
This may have to do with the fact that the executable runs the script from memory. It is possible PowerShell does not look for the language files in this case.
We will need to investigate.
David
We will need to investigate.
David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- juneblender
- Posts: 93
- Last visit: Thu Mar 30, 2017 8:54 am
Re: Powershell Studio - Include Language Files (.psd1) in exe
This is a great question, Renato. I'm going to blog the answer.
I found the clue in this error message:
"The FileName parameter is required when Import-LocalizedData is not used in a script."
So, when you're going to package the script in an .exe, add the FileName parameter of Import-LocalizedData, even when the name of the .psd1 matches the script name.
Also, when I built my exe, but ran it from a different directory, ...
e.g. PS C:\> .\Scripts\CoolScript\MyCoolScript.exe -...
PowerShell looked for the .psd1 with the specified filename in the directory from which I was running, e.g. C:\, instead of the script directory, C:\Scripts\CoolScript. This doesn't happen with a .ps1, but it does with an .exe.
So, I wanted to use the BaseDirectory parameter of Import-LocalizedData, too.
To get the base directory, I tried to use $PSScriptRoot and $MyInvocation.MyCommand.Path, but because they're host-specific, they don't work in an .exe. To fix this, I used the Get-ScriptDirectory snippet in PowerShell Studio, which uses a $HostInvocation variable.
Here is the final fix:
I found the clue in this error message:
ERROR: Import-LocalizedData : The FileName parameter was not specified. The FileName ERROR: parameter is required when Import-LocalizedData is not called from a script ERROR: file.And, the solution in help for Import-LocalizedData:
"The FileName parameter is required when Import-LocalizedData is not used in a script."
So, when you're going to package the script in an .exe, add the FileName parameter of Import-LocalizedData, even when the name of the .psd1 matches the script name.
Also, when I built my exe, but ran it from a different directory, ...
e.g. PS C:\> .\Scripts\CoolScript\MyCoolScript.exe -...
PowerShell looked for the .psd1 with the specified filename in the directory from which I was running, e.g. C:\, instead of the script directory, C:\Scripts\CoolScript. This doesn't happen with a .ps1, but it does with an .exe.
So, I wanted to use the BaseDirectory parameter of Import-LocalizedData, too.
To get the base directory, I tried to use $PSScriptRoot and $MyInvocation.MyCommand.Path, but because they're host-specific, they don't work in an .exe. To fix this, I used the Get-ScriptDirectory snippet in PowerShell Studio, which uses a $HostInvocation variable.
Here is the final fix:
function Get-ScriptDirectory {...} Import-LocalizedData -BindingVariable msgTable -FileName Test-UserMsgs.psd1 -BaseDirectory (Get-ScriptDirectory) if (!$msgtable) { throw "Can't import localized user messages." }Let me know if this works for you.
- renato.bacchi
- Posts: 8
- Last visit: Tue Oct 30, 2018 1:46 am
Re: Powershell Studio - Include Language Files (.psd1) in exe
wow you guys are awesome, thx for the help!!
- renato.bacchi
- Posts: 8
- Last visit: Tue Oct 30, 2018 1:46 am
Re: Powershell Studio - Include Language Files (.psd1) in exe
can you tell me what exactly your get-scriptdirectory function does?
it does not work if i try it loke this
function Get-ScriptDirectory
{
Split-Path -Parent $HostInvocation
}
it does not work if i try it loke this
function Get-ScriptDirectory
{
Split-Path -Parent $HostInvocation
}
- renato.bacchi
- Posts: 8
- Last visit: Tue Oct 30, 2018 1:46 am
Re: Powershell Studio - Include Language Files (.psd1) in exe
Our Get-ScriptDirectory looks for a packager engine variable that gives the path of the executable. The normal methods will not work since the script is ran from memory.
David
David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.