Execute-ProcessAsUser CMD.exe minimize or silent

Hello, first time poster/long time user of PSADT.

Trying to help desktop guys with some migration of users. We have the following line which works but the CMD is displayed. We have 5 folders they would like copied local. Project to migrate user APPDATA to local. Teams, Adobe, Ivanti and other apps work much better local. Especially now with everyone working from home. What would be ideal is a “-WindowsStyle Hidden” like Execute-Process.

Added “start /min” which helps a little but CMD still pops up a window.

$ieResults = Execute-ProcessAsUser -Path “C:\Windows\system32\cmd.exe” -Parameters “/c start /min robocopy $homeShare\Applic~1\Microsoft\Intern~1\ “”$pPath\Appdata\Roaming\Microsoft\Internet Explorer”" /E" -Wait -PassThru

If anyone can offer any ideas, it would be greatly appreciated.

Thats because you’re telling powershell.exe to open cmd.exe to open robocopy.exe to copy content of a folder into another folder.

You can just do it all with powershell. You should also avoid using dos paths. They add unnecessary complexity.

# Prepare path variables
[string]$contentToCopy = [System.IO.Path]::GetFullPath("$homeShare\Applic~1\Microsoft\Intern~1\")
[string]$destinationPath =  "$pPath\Appdata\Roaming\Microsoft\Internet Explorer"
# Validate paths and copy files. Throw Error if paths arent valid
if ($contentToCopy -and (Test-Path $contentToCopy) -and (Test-Path $destinationPath)) {
    Write-Log "Copying Internet Explorer user settings"
    Copy-File -Path "$($contentToCopy)*" -Destination $destinationPath -Recurse -ContinueOnError $false -ContinueFileCopyOnError $false
} else {
    Write-Log "Failed to resolve the path to content on user`'s share!" -Severity 3
    Throw "Failed to resolve the path to content on user`'s share!"

SCCM Admin account does not have access to user $homeShare. Test-Paths fail. That’s why we have to do AsUser. If we used robocopy directly, still the same issues of the window pop-ups. Thanks.

If thats the case then the solution will be a little more complicated.

The problem here is that Execute-ProcessASUser uses task scheduler to instantly run a task under a different user. Task scheduler by default doesn’t hide the programs or windows. You would need a silent launcher. Simplest way to do this would be via a vbs script since those can be completely silent. You would call wscript.exe through Execute-ProcessAsUser with the vbs script as the path. In the vbs script you would copy the files.

1 Like

@luki1412 I was stuck with this idea to run cmd and/or robocopy. Try to copy what my desktops guys have discovered when we build these tools to help automate their tasks. Thanks for opening my eyes to another way. Much appreciated.

You’re welcome. Glad I helped. Cmd and powershell are console applications unlike wscript so they need another application to start them silently otherwise they open via conhost.exe which is visible. So if you want still use those, you would need to write/find simple silent applauncher similar to the deploy-application in our toolkit. That however adds another problem and that is that parameters need to go from powershell to task scheduler to app launcher to cmd/powershell and escaping those would be a nightmare unless you use some local config for it.

Guess, you can see why I signed up today and asked this question. I will try to be active on here and help where possible.

Can AutoHotKey, WinHide make console windows invisible? I have used this in the past to hide downloader or self-extracting windows before.


From PSADT, I use -NoWait on Execute-Process so AHK launches and waits for the window to pop, hides it and then exits.

It is a little “dirty” but it works.

That’s interesting. I will have to give it a read. Thanks