By Carolyn / Last Updated October 10, 2023

How do I lock my remote computer in PowerShell?

 

Is there a PS script for locking a user's workstation that is on the same domain?

- Question from Reddit

https://www.anyviewer.com/screenshot/others/illustration/powershell-logo.png

Working remotely has become the norm for people at work. People often need to control other devices remotely for work or other things. To ensure that their information is secure, in many cases they will want to lock down the remote computer. This is when PowerShell can be used to do so. So how do I lock my remote computer in PowerShell? The approach of  lock remote computer PowerShell will be introduced in this article.

How to lock remote computer PowerShell

When performing remote access, users come across the need to lock the remote computer to secure their information. Using PowerShell can help you do this. However, you need to know to run the script that locks down the remote computer in order to succeed. To lock or shut down the remote computer using PowerShell, you need to specify a list of systems that need to be locked or shut down. Follow the steps below to lock or shut down your remote computer.

Part 1. Lock remote computer

If you want to PowerShell lock remote computer Windows 10 and 11, just enter the lock command.

Step 1. Make sure you have the necessary permissions to run PowerShell commands on the remote computer.

Step 2. Right-click on "Start" to open the menu and select "Windows PowerShell (Admin)".

https://www.anyviewer.com/screenshot/windows/windows-powershell-admin.png

Step 3. Run the rundll32.exe command on the remote computer using the invoke-command cmdlet. After inputting the following command, hit the "Enter" key.

Invoke-Command -ComputerName RemoteComputerName -ScriptBlock {rundll32.exe user32.dll, LockWorkStation}

Note: Remember to replace remote_computer with the computer name or IP address of your remote computer.

This command will execute the rundll32.exe command on the remote computer, which will lock the remote computer and require the user to enter a password to unlock it. Ensure that you have the required permissions and access rights to execute remote commands on the target computer and that PowerShell Remote Actions are enabled on the remote computer to enable it to work properly. If you have not yet established a session, you may be prompted to enter credentials to connect to the remote computer.

Part 2. Shout down remote computer

If you want to shut down the remote computer via PowerShell that is also possible, you will see the steps to shut down the remote computer using it.

Step 1. Simultaneously press "Win+X" to open the menu and select "PowerShell (Admin)" from the menu.

https://www.anyviewer.com/screenshot/windows/windows-powershell-admin.png

Step 2. After inputting the following command, hit the "Enter" key.

Stop-Computer -ComputerName remote_computer

/screenshot/windows/stop-computer.png

Note: Remember that you will need to replace remote_computer with the computer name or IP address of your remote computer.

Step 3. Now let's check the help of this cmdlet and for that enter the following command to stop the computer via PowerShell:

Get-Help Stop-Computer

/screenshot/windows/get-help-stop-computer.png

If someone is currently working on the remote computer, you will receive an error message. To resolve this issue, you can add a key, which will perform a forced shutdown.

Stop-Computer -ComputerName remote_computer -Force

Note: Also, remember that you need to replace remote_computer with the computer name or IP address of your remote computer.

This Credentialswitch can be used if you need to perform a shutdown on behalf of a specific account:

Stop-Computer -ComputerName remote_computer -Credential root/sem -Force

Note: Root is the name of the domain and sem is the username. You also need to replace remote_computer with the computer name or IP address of your remote computer.

AnyViewer: Easier way to remotely lock & shutdown remote computers

Now you have got the solution to lock the remote computer. Although the above procedure seems very simple, it is very difficult to repeat it and remember the code every time you need to lock the remote computer. So it is recommended that you explore alternatives to PowerShell. AnyViewer would be highly recommended. AnyViewer is an all-in-one, secure, and free remote desktop software. Using it users can easily lock, shut down, or reboot remote devices with a single click.

At the same time, users can also easily achieve unattended remote access with one-click control. It also offers a range of great features during remote access, such as file transfer, real-time synchronization of remote device sounds, text chat, multi-monitor support, and screen sharing.

Not only is AnyViewer compatible with a wide range of systems, but it also allows users to connect to remote computers and perform a variety of operations over the same LAN or different networks.

Download Freeware Win PCs & Servers
Secure Download

Step 1. Download, install, and run AnyViewer on both of your devices.

https://www.anyviewer.com/screenshot/anyviewer/connect.png

Step 2. Go to "Log in" and select "Sign up" to create an AnyViewer account and log in on both devices.

https://www.anyviewer.com/screenshot/anyviewer/log-in-anyviewer.png

Step 3. After successfully logging into AnyViewer. Your device will be allocated to the account with which you logged in automatically.

https://www.anyviewer.com/screenshot/anyviewer/free-editions.png

Step 4. Go to “Device” and select the target device you want to connect, then click “One-click control” to achieve unattended remote access.

https://www.anyviewer.com/screenshot/anyviewer/connect-to-my-devices.png

Step 5. Click on "Operation" and then you can see "Lock" and “Shut down” in the list and click on it. You can lock or shut down your remote computer instantly.

https://www.anyviewer.com/screenshot/anyviewer/operation.png

★Tips: You can upgrade your account to a Professional or Enterprise plan to get more benefits:
Assign more devices and be able to access more devices unattended.
Enjoy remote access connections in Privacy Mode. This means that you can black out and disable the mouse and keyboard of the remote computer.
A single computer can control numerous wireless devices at the same time.
Enjoy file transfers with no limit on the number of files.
Enjoy faster file transfer speeds.
Create groups for corporations to handle huge numbers of devices more efficiently.
Enjoy higher-quality images.
...

​​​​​​

Conclusion

This article explains how to lock remote computer PowerShell. But the PowerShell script to lock remote computer is always complicated and it is very difficult for users to remember it. So it is highly recommended that you explore alternatives to PowerShell. AnyViewer makes it easy to lock, shut down, or reboot a remote computer. Not only that, AnyViewer allows you to do much more with ease. Using AnyViewer is also very easy and convenient, so download it and try it out!