Forum Discussion
SJamal85
Jul 07, 2022Copper Contributor
Powershell script is not working using PSF
Hi Everyone,
I am trying to run a powershell script using the PSF binaries in a MSIX package. However, it is not working. The powershell script on its own is working as expected. Can someone look into the config.json file I am using.
The content of the config.json file is:
{
"applications": [
{
"id": "TRMANIFEST",
"executable": "VFS/ProgramFilesX86/Maersk Denizcilik A.S/TRManifest_Setup/TRManifest2009.exe",
"stopOnScriptError": false,
"startScript":
{
"scriptExecutionMode": "-ExecutionPolicy Unrestricted",
"scriptPath": "MapDrive.ps1",
"showWindow": true,
"runInVirtualEnvironment": false,
"waitForScriptToFinish": true,
"timeout":10
}
}
]
}
Let me know if there is something wrong in this file.
- 1) The PsfScriptLauncher.ps1 file is missing from the root of the package. This file is part of the PSF. This file is required as it will be executed in PowerShell to then run your script.
2) The timeout value in the Json is too low. The 10 represents 10ms which is generally not long enough for PowerShell to even start up. Increase to 10000 to get 10 seconds, for example.
3) Add a sleep to the end of the powershell start-sleep 60 would give you time to see any error messages in the PowerShell window should they occur. If so, the timeout value will have to increase more.
4) The Unrestricted option in the json will cause a problem if there is any GPO setting the PowerShell restriction policy. As is in your ps1 file, the Bypass option might be a better choice
5) If you still have issues, use the Sysinternals DebugView tool which can display debugging information emitted by the PsfLauncher as it tries to start your script. Start that tool, then launch the shortcut.
- Aniket_Banerjee
Microsoft
Hi
Can you share the package (via messages), the script and manifest file. It will help us debug it deeper.
Thanks- Siva116Brass Contributor
Hi Aniket_Banerjee TIMOTHY_MANGAN
Application Name : Notepad++
Requirement : copying file config.xml (to suppress auto updates)
File Location: $Env:ProgramFiles\WindowsApps\Notepad_1.0.0.0_x64__vwr83xx145m1c\VFS\ProgramFilesX86\Notepad++\config.xml
File Destination : %localappdata%\Packages\Notepad_vwr83xx145m1c\LocalCache\Roaming\Notepad++
==============================
I am trying to copy config.xml file from MSIX package install directory location to users localappdata. the file contains settings to suppress auto update. I did everything required, but not able to succeed to achieve the output. Could you please suggest where I am missing. I have attached config.json, copyfile.ps1, MSIX PSF files pictures, please review.
I followed below link:
https://www.alexandrumarin.com/add-powershell-scripts-in-msix-with-psf/
https://docs.microsoft.com/en-us/windows/msix/psf/run-scripts-with-package-support-framework
https://techcommunity.microsoft.com/t5/msix/notepad-automatic-language-configuration/m-p/3558411
but no luck. please assist.
THANKS in Advance.
- KunalPriv8Copper ContributorHi Siva,
was this resolved?
can you share the PS script if it got success.
- First, it would help to know what version of the PSF (or what version of tooling you used) is involved. We have better support for scripting in the TimMangan branch on GitHub than in the original Microsoft branch.
Second, there are no obvious errors in your json syntax, however, here are some things to consider:
* The runInVirtualEnvironment setting is ignored. Microsoft removed support for this. In my fork, this script will always run inside the container. Out of container powershell is now possible starting in PSF v2022.06.08 but not through this scripting method. But if you are just mapping a drive it shouldn't matter if it runs inside or outside.
* The timeout value is in MS, so if you intended 10 seconds multiply by 1000.
* As specified, your ps1 file would need to be placed at the root folder of the package.
* The PSF StartingScriptWrapper.ps1 file must also be placed there.- SJamal85Copper Contributor
TIMOTHY_MANGAN , Aniket_Banerjee I am attaching few screenshots, please check if I am making any mistakes here.
- 1) The PsfScriptLauncher.ps1 file is missing from the root of the package. This file is part of the PSF. This file is required as it will be executed in PowerShell to then run your script.
2) The timeout value in the Json is too low. The 10 represents 10ms which is generally not long enough for PowerShell to even start up. Increase to 10000 to get 10 seconds, for example.
3) Add a sleep to the end of the powershell start-sleep 60 would give you time to see any error messages in the PowerShell window should they occur. If so, the timeout value will have to increase more.
4) The Unrestricted option in the json will cause a problem if there is any GPO setting the PowerShell restriction policy. As is in your ps1 file, the Bypass option might be a better choice
5) If you still have issues, use the Sysinternals DebugView tool which can display debugging information emitted by the PsfLauncher as it tries to start your script. Start that tool, then launch the shortcut.