Minimize all windows on remote computer using PowerShell

Tom Sasson 1 Reputation point
2020-09-22T10:41:59.81+00:00

Hi, I am trying to connect remotely to a machine using SSH and executing PowerShell command to minimize all windows on the remote computer.

I am using Python, and SSH protocol of paramiko package.

Usually PowerShell commands do work for me, except for this one.

This is what I was trying, and works locally but not remotely:

ssh_client.execute_command('powershell -ExecutionPolicy Bypass -command "& { $x = New-Object -ComObject Shell.Application; $x.minimizeall() }"') 

Could anyone suggest what is wrong, or perhaps another solution to minimize all windows?

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,553 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 34,431 Reputation points
    2020-09-23T01:10:32.703+00:00

    That call will not "minimize all windows on the remote computer", it will minimize all windows that were launched by the interactive desktop shell for the user who executes the call. An SSH session is launched by the OpenSSH service, not a desktop shell. I don't think that's going to work for you.

    You could try using the task scheduler and create a task that executes Powershell and your script. Set the task to run as the use "INTERACTIVE". Then on the local PC run "schtasks /run /s remote-pc-name /tn Your-Task-Name". The desktop user will see a Powershell window pop up when that runs.


  2. Rich Matheisen 46,811 Reputation points
    2020-09-23T14:23:34.44+00:00

    See if your Linux distribution is supported. If so, install it on the Linux machine and use it (pretty much) the same way you would on Windows. There are some things that you can't do but New-PSSession and Invoke-Command (for example) are usable.

    installing-powershell-core-on-linux

    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.