Powershell Script failing

Ed7 96 Reputation points
2021-09-03T13:30:36.477+00:00

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 for business Windows Client for IT Pros Devices and deployment Set up, install, or upgrade
Microsoft 365 and Office Development Office JavaScript API
Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
Developer technologies .NET Other
{count} votes

6 answers

Sort by: Most helpful
  1. AllenLiu-MSFT 49,311 Reputation points Microsoft External Staff
    2021-09-06T06:17:37.707+00:00

    Hi, @Ed7
    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.

    0 comments No comments

  2. Ed7 96 Reputation points
    2021-09-06T08:14:35.007+00:00

    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

    0 comments No comments

  3. Ed7 96 Reputation points
    2021-09-06T13:06:42.93+00:00

    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.

    0 comments No comments

  4. AllenLiu-MSFT 49,311 Reputation points Microsoft External Staff
    2021-09-07T07:54:35.057+00:00

    Hi, @Ed7
    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://learn.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.

    0 comments No comments

  5. Ed7 96 Reputation points
    2021-09-07T08:16:44.843+00:00

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.