Form-based script/exe running with elevated credentials

I have a form-based powershell script that I packaged in Powershell Studio a while back and I have been testing whether I can migrate it to Powershell Tools. The application does operations that require elevated/admin credentials so we normally run the program from an admin prompt.

I have ported the code and everything seems to work “unelevated” until you hit submit and then you get a runtime error which I think I’ve tracked down to “access denied” on the operation being submitted.

The form/application does not work at all when I run the script from an elevated powershell window or package it as an exe and run it elevated.

Is there something that needs to be done to allow a form/application to run elevated?

Have you tried to set the Require Elevation property of the package config? Not sure if that would be different than elevating manually.

https://docs.poshtools.com/powershell-pro-tools-documentation/packaging/package.psd1#config-file-schema

Hi Adam
Thanks for the pointer to the package config. While it didn’t fix my issue, it was good to incorporate it in the build because we need to prompt the user for elevated credentials if they are not being used.
I actually discovered that the issue was related to the order of my form code - I had the form initialization and load functions at the beginning of the script. Moving them to the bottom so that all form element functions were loaded/read before the form initialized solved the issue.