CDrummeRG Top Student
Top Student
3 2 1 0
Message 1 of 3
2,471
Flag Post
HP Recommended

Solved!

Task: script to call Powershell as Admin and run powershell script- Failed to execute Script task

T630
Other

2017-04-20 10:35:38

Successfully sent task to the Device Management Gateway 2017-04-20 10:35:44 Task has been retrieved by the Agent. 2017-04-20 10:36:18 Successfully configured BootCommand to "disable". 2017-04-20 10:36:18 Successfully configured WFType to "". 2017-04-20 10:36:18 Successfully executed ConfigWriteFilter task. 2017-04-20 10:36:18 Successfully executed common task. 2017-04-20 10:36:18 Map repository to: Master Repository 2017-04-20 10:36:18 Successfully sent task to the Device Management Gateway 2017-04-20 10:37:45 Task has been retrieved by the Agent. 2017-04-20 10:37:50 Deploy files using repository Master Repository. 2017-04-20 10:37:50 Successfully downloaded RenameTC.ps1 to C:\Windows\ from /Repository/Files/ToDeploy/Make a Change Template. 2017-04-20 10:37:50 Successfully executed DeployFiles task. 2017-04-20 10:37:50 Successfully executed common task. 2017-04-20 10:37:50 Successfully sent task to the Device Management Gateway 2017-04-20 10:37:56 Task has been retrieved by the Agent. 2017-04-20 10:38:06 Execution result (below): 2017-04-20 10:38:06 C:\Windows>powershell C:\Windows\RenameTC.ps1 2017-04-20 10:38:06 C:\Windows\RenameTC.ps1 : File C:\Windows\RenameTC.ps1 cannot be loaded 2017-04-20 10:38:06 because running scripts is disabled on this system. For more information, see 2017-04-20 10:38:06 about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170. 2017-04-20 10:38:06 At line:1 char:1 2017-04-20 10:38:06 + C:\Windows\RenameTC.ps1 2017-04-20 10:38:06 + ~~~~~~~~~~~~~~~~~~~~~~~ 2017-04-20 10:38:06 + CategoryInfo : SecurityError: (:) [], PSSecurityException 2017-04-20 10:38:06 + FullyQualifiedErrorId : UnauthorizedAccess 2017-04-20 10:38:06 Failed to execute Script task. 2017-04-20 10:38:06 ErrorCode: 14004022, Error Detail: Command line error. 2017-04-20 10:38:06 Failed to execute common task. 2017-04-20 10:38:06

ErrorCode: 14004022, Error Detail: Command line error.

 

I Can Successfully run this .Ps1 logged on as the Admin and User accounts locally. the script is not the issue. the issue is with the coding inside the Task -the code is:

 

powershell -noprofile -command "&{start-process Powershell -ArgumentList ' -noprofile -file c:\Windows\RenameTC.ps1' -verb RunAs}"

 

this failes to allow the script to run being denied access. i have told this script to run as Admin (built in Admin account) and also (SYSTEM) as well. both fail out trying to run this task with the info i posted from the Task View Sequence. I need to be able to run this as part of my imaging task sequence. doing this manually is not really an option. 

 

How can i get the Script to Open up powershell as admin and run a powershell script without failing?

2 REPLIES 2
CDrummeRG Top Student
Top Student
3 2 1 0
Message 2 of 3
2,450
Flag Post
HP Recommended

Solved!

Task: script to call Powershell as Admin and run powershell script- Failed to execute Script task

HPDMscript1.JPG

 

HPDMscript2.JPG

 

this is the script im sending from HPDM. this fials out using both the "Run AS:" with both Admin and System

my .ps1 will run fin if i login as Admin open Poweshell as Admin and run the file.

It will also run using the ablove content inside of CMD. while this is failing using it from HPDM Script is confusing me.

 

Reply
0 Kudos
CDrummeRG Top Student
Top Student
3 2 1 0
Message 3 of 3
2,433
Flag Post
HP Recommended

Solved!

Task: script to call Powershell as Admin and run powershell script- Failed to execute Script task

After Further troubleshooting I started the script from scratch. this was a case of making thing harder than i should have.  I was attempting to run powershell as Admin and that was cauing the issue. I changed the script to just : 

 

powershell.exe -noprofile -executionpolicy bypass -file C:\Windows\renameTC.ps1

 

this ran powershell from the batch window and set the -execution policy to bypass prompts and allow the file to run without issue.

 

So my Make a Change Template sequence goes like this:

 

1. disable write filter

2. copy file from repository to the "C:\Windows" Dir (place it anywhere you want.)

3. run the script: powershell.exe -noprofile -executionpolicy bypass -file C:\Windows\renameTC.ps1

4. Delete the RenameTC.ps1 file

5. reboot

6. enable Write filter

 

This completes without error. have a great day and hope this helps someone with using the script to call powershell and run a powershell script on a T630 Thin Client Windows 10 IoT 64bit  using  HPDM 4.7 SP6

 

 

 

Reply
0 Kudos
Tags (2)
† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation