Invoke-CommandAs script not automatically completing during MDT image

Joseph Mastrangelo 0 Reputation points
2023-12-11T15:32:59.9933333+00:00

Good morning. I have assumed responsibility for MDT at my workplace and so far things have been smooth. I updated to the latest Windows 11 21h2 in our test environment and now I am having a problem with a script to reset the LAPS password of a device. This issue does not happen on the old version of Windows 11, and unfortunately I don't know what version it is outside of 21h1. We are using a Powershell script which imports the modules Invoke-CommandAs and AdmPwd.PS. Picture of the error is attached.

When the script functions correctly, it just runs and quits the window. The problem is that there is now a security warning and it requires input from the user.

On MDT, the quiet install command is: powershell -ExecutionPolicy Bypass -file .\install.ps1

Note that this works perfectly on an older version of Windows 11, but on the 21h2 October version, it does not.

The script install.ps1:

Import-Module "$PSScriptRoot\Invoke-CommandAs\Invoke-CommandAs.psd1"
Import-Module AdmPwd.PS

Invoke-CommandAs -AsSystem -ScriptBlock {
    Reset-AdmPwdPassword -ComputerName $env:COMPUTERNAME -WhenEffective (Get-Date).AddDays(-1)
}


I have tried including Unblock-File in this script, before Import-Module, and tunneling it to the source directory of Invoke-CommandAs, and it hasn't helped. I am still learning how to write and interpret powershell, so I am pretty stumped on how to fix this problem. If there is any information that I left out I am sorry. The server which hosts our deployment shares has an execution policy of RemoteSigned. I have also found the source files of these scripts in our file repository and unblocked them all through Properties. Thanks in advance for any help you can provide me in getting this process back up and running. MicrosoftTeams-image (7)

Windows for business Windows Client for IT Pros Devices and deployment Set up, install, or upgrade
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AllenLiu-MSFT 49,311 Reputation points Microsoft External Staff
    2023-12-12T01:56:58.45+00:00

    Hi, @Joseph Mastrangelo

    Thank you for posting in Microsoft Q&A forum.

    It seems it's a PowerShell related issue, I find below thread, it mentioned some machines treat UNC paths as the big bad internet, so PowerShell treats them as remote files. You can either disable this feature on those servers (UncAsIntranet = 0,) or add the remote machines to your trusted hosts. We may try the solutions to see if they help.

    https://stackoverflow.com/questions/728143/ignore-security-warning-running-script-from-command-line


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Add comment".

    0 comments No comments

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.