Forum Discussion
Deploying PS Script as Application Doesn't Work
- Apr 24, 2025
Your problem is that you are copying a file from a network share. This is because the script will run as local system account. As such you need to test your script as local system. This blog will show you how to do that. How to Access the Local System Account - Recast Software
You can solve this but including the license file with the script/setup. That is the simplest solution.
1- determine if you really need the script to run as the user or if you can adapt it to run as System.
In our case, access to a network share required a proper user session.
2- Before you tweak MECM settings, you can test locally how your script behaves under the SYSTEM account:
PsExec64.exe -i -s powershell.exe
This launches a PowerShell window as SYSTEM.
Run your script there.
If it fails there, it will fail in MECM. Now you know it’s truly a permissions/context problem.
3- Modify Script to Authenticate to the Network Share
Instead of relying on inherited session authentication, explicitly authenticate inside the script:
$User = "domain\useraccount" $PWord = ConvertTo-SecureString -String "password" -AsPlainText -Force $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord New-PSDrive -Name "Z" -PSProvider "FileSystem" -Root "\\server\share" -Credential $Credential Copy-Item -Path "Z:\yourfile.lic" -Destination "C:\Program Files\YourApp\Licenses" -Recurse Remove-PSDrive -Name "Z"
https://www.tech2geek.net/deploying-a-powershell-script-as-an-application-in-mecm-why-it-fails-and-how-to-fix-it/