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

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,605 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,575 questions
Microsoft Deployment Toolkit
Microsoft Deployment Toolkit
A collection of Microsoft tools and documentation for automating desktop and server deployment. Previously known as Microsoft Solution Accelerator for Business Desktop Deployment (BDD).
852 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
936 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,449 questions
{count} votes

6 answers

Sort by: Most helpful
  1. AllenLiu-MSFT 42,826 Reputation points Microsoft Vendor
    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 42,826 Reputation points Microsoft Vendor
    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.