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.
running powershell script in the user context is kind of tricky because of the execution-policy and user rights.
is it possible to post the script here?
i would advice using app-deployment toolkit as it will post all log files in the c:\windows\logs folder or enable
or
you can add this line att the top of you powershell script and run it to see what goes wrong
Start-Transcript -Path c:\temp\log.txt -Append
- dkingsb4Apr 25, 2025Copper Contributor
Yeah it's a pretty basic PS script.
# Define variables$SourcePath1 = "<path/file>"$DestinationPath1 = "<path/file>"$SourcePath2 = "<path>"$DestinationPath2 = "<path"# Copy files from source to destinationtry {Copy-Item -Path $SourcePath1 -Destination $DestinationPath1 -Recurse -ForceWrite-Host "Files copied successfully from '$SourcePath1' to '$DestinationPath1'."Copy-Item -Path $SourcePath2 -Destination $DestinationPath2 -Recurse -ForceWrite-Host "Files copied successfully from '$SourcePath2' to '$DestinationPath2'."}catch {Write-Error "Error copying files: $($_.Exception.Message)"exit 1- Garth-MVPApr 27, 2025Iron Contributor
did you test the script as the local system account? Are any of the paths Unc?
- dkingsb4Apr 28, 2025Copper Contributor
So when I was testing this initially I tested using the signed in user account at least just to make sure the syntax was correct, which it was. Knowing that MECM was using the SYSTEM account, I made the assumption that the issue I was having with doing this through MECM was just that - so I never tested directly with the SYSTEM account. However, using your instructions, I did find that this did indeed fail. Once I gave "All Domain Computers" read/execute on the source location share, the SYSTEM account was successful in copying over the files. I was then able to make this work directly within MECM using the script.
I also made an application, one to install the software I'm looking to install, and a second one to invoke the script to copy the files. This works, but I did find that it seems to fail initially because the script tries to run at the same time as the software install (therefore the target directories don't exist). This is despite me specifying that the software installation is to be a prerequisite. A second run at the script install after the software is in place is successful.
I'm sure there's a better way of accomplishing this as well. I'll have to keep tinkering with it to get it exactly the way I want it, but this works for now.
- AhmedLSApr 26, 2025Copper Contributor
if you are running the script in user context the $DestinationPath is very important. unless the user has rights to the folder it wont work. anywhere outside the user profile actually wont work unless the user is admin.
you wrote that you ran the script manually and it worked. did you run it as a user or admin