question

Ed-2021 avatar image
0 Votes"
Ed-2021 asked AllenLiu-MSFT commented

Powershell Script failing

Hello,

I am trying to run a powershell script in MDT, however it is always failing. This script is to remove some defaults windows apps,.
Could someone help me please?


129153-image.png


windows-serverwindows-server-powershellmem-mdtoffice-js-devwindows-wcf
image.png (215.4 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you run your script from a PowerShell window (i.e. not from MDT) does it succeed? If not, does it work if you run it from an elevated (i.e. "Run as administrator") PowerShell window?

0 Votes 0 ·
AllenLiu-MSFT avatar image
0 Votes"
AllenLiu-MSFT answered

Hi, @Ed-2021
Thank you for posting in Microsoft Q&A forum.

You may try below to bypass the execution policy:

 cmd.exe /c  powershell.exe -executionpolicy bypass -file "%SCRIPTROOT%\Windows_Cust.ps1"

Also, I see you also have a step to run powershell script, have you tried that and what is the result?

If above doesn't help, you may check smsts.log for more details.


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Ed-2021 avatar image
0 Votes"
Ed-2021 answered

Hi @AllenLiu-MSFT

Thank you for your help.

I did try the powershell but it also failed. I will try the commands you mentioned and I will come back to you.

Thank you

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Ed-2021 avatar image
0 Votes"
Ed-2021 answered

Hi @AllenLiu-MSFT

Unfortunatly the issue still remains with this error code.


129596-image.png


This script is for removing the default apps, I have tried both the command line and the powershell to run the script and I always get the same error.
.Net Framework and Powershell are enabled in the Features. but no solution.

This is the command line I have in Run Command Line:

cmd.exe /c powershell.exe -executionpolicy bypass -file "%SCRIPTROOT%\Windows_Cust.ps1"

and in the Run PowerShell script I have tried both:

Windows_Cust.ps1

or %SCRIPTROOT%\Windows_Cust.ps1


This is my script
129589-windows-custps1.txt




Not sure what can be the issue.


image.png (24.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AllenLiu-MSFT avatar image
0 Votes"
AllenLiu-MSFT answered

Hi, @Ed-2021
Thank you for posting in Microsoft Q&A forum.

Have we tried to run the script manually, outside the MDT environment, does it work well?
And try to check more details in smsts.log.
You can add SLSHARE in CustomSetting.ini to get the log file, SLSHARE instructs MDT to copy the log files to a server share if something goes wrong during deployment, or when a deployment is successfully completed.
https://docs.microsoft.com/en-us/windows/deployment/deploy-windows-mdt/create-a-windows-10-reference-image#the-customsettingsini-file


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Ed-2021 avatar image
0 Votes"
Ed-2021 answered AllenLiu-MSFT commented

HI @AllenLiu-MSFT

Yes I have run the script in different laptops and it works fine and performs all the desirable actions. Only in the deployment it does not run.
It has been a big headache.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Does MotoX80's suggestion help? Or do you check the smsts.log for more details?

0 Votes 0 ·
MotoX80 avatar image
0 Votes"
MotoX80 answered

Assuming that cmd.exe will run, capture stdout and stderr to see if there is some error in there.

 cmd.exe /c powershell.exe -executionpolicy bypass -file "%SCRIPTROOT%\Windows_Cust.ps1" 1 > C:\YourLogFolder\MyScript.log 2>&1


Also add a transcript into your .ps1 code.

https://www.tutorialspoint.com/how-to-use-a-transcript-in-powershell

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.