Stepwise Tutorial: How to Use CMD Delete Folder on Remote Computer

In this post, we provide the way on using CMD delete folder on remote computers on Windows 11, 10, 8, 7. If you happen to need it, read this post to know the concrete steps.

Ellie

By Ellie / Updated on November 21, 2022

Share this: instagram reddit

Want to delete files/folders remotely with CMD

 

 

Hello everyone, I'm trying to delete a folder on remote machines using CMD on Windows 10. I don't have exclusive rights to do everything I'd like to so I've only been able to come up with using CMD as an alternative.  I'm open to suggestions to try out. Any insight you all can provide would be much appreciated!  

- Question from Stack Overflow

Delete Files Folders

How to use CMD delete folder on remote computer

By using CMD delete folder on remote computer on Windows 11, 10, 8, 7..., here we sort out 2 options. One is to use the command line directly, and another is to achieve a remote connection to the remote computer and use the command line then. Keep reading.

Option 1. Delete folders/files on remote computers with the Remove-Item command

It is easy to delete the files on remote computers using Powershell, there is a command Remove-Item deletes files, folders, variables, registry keys, and aliases, let’s learn more about this command with examples.

Examples:

✍Remove-Item -path "c:\temp\raj.txt"

The above example removes the raj.txt file in C:\temp drive.

✍Remove-Item -Path C:\temp\* -Force

The above example removes all the files under C:\temp including hidden ready-only files as we declared the parameter -force at the end.

✍Remove-Item -Path C:\app\download\* -Force -Recurse

The Above example removes all files under C:\app\download including subfolders and files recursively as we defined the parameter -Recurse.

The above shows how you use Remove-Item command on local computer, next, let's see how to use it to delete files/folders on remote computers. 

Step 1. If you need to delete files on multiple remote machines, just create a file for storing all the servers or multiple machines list. Here we name the file as Allservers.txt and saved it in my local machine c:\temp\Allserver.txt.

Allservers

Step 2. Right-click Start, and then choose Windows PowerShell (Admin).

Windows PowerShell Admin

Step 3. If you want to remove all files under C:\softwares\adobe including subfolders and files recursively on the listed remote computers in the file allservers.txt, type in the following script:

#remote machines list
$machines= Get-Content -Path "C:\temp\AllServers.txt" 

foreach ($onemachine in $machines)
  {
      Write-Host "Currently the script is copying files on" $server
Remove-Item -Path "\\sourcemachine\c$\softwares\adobe" -Force -Recurse
   }

The Above example script will remove all the files you designated. You can also delete other files by replacing the file name.

Option 2.  Delete folders/files on remote computer via Remote Desktop Connection

The steps of this method is divided into 2 parts. The first part is to achieve remote connection with Remote Desktop Connection and the second part is about deleting folders remotely.

Part 1. Establish remote desktop connection

By using Remote Desktop to establish a remote desktop connection, it needs to be mentioned that 2 devices should be on the same LAN, otherwise you need to perform port forwarding.

Step 1. In the PC that you want to control, click the “Start” button and go to “Settings” > “System” > “Remote Desktop”. Here you can see the PC name of this computer. Keep it in mind, as you need  to use it for accessing this computer

Remote Desktop

Step 2. Drag the slider to enable Remote Desktop. Then, click “Confirm”.

Confirm

Note: By default, any user who has an administrative account on the host PC is allowed to access it, thus you need to set a strong password for your administrative account.

Step 3. Search  “Firewall” in the Search box, choose Windows Defender Firewall, and click “Allow an app through Windows firewall”.

RDC

Step 4. Click “Change Settings” and Check Private and Public for Remote Desktop. Then, click “OK”.

OK

After enabling Remote Desktop and allowing the tool in the firewall, you can run Remote Desktop Connection to control the computer. 

Step 5. In the PC that you use to control another PC, input “remote desktop connection”, double click "Remote Desktop Connection" to open it.

RDC

Step 6. Now, you’ll be in Remote Desktop Connection. Type the PC name or the IP address of the remote PC  and click "Connect". 

Enter IP of the Host Computer

Step 7. Then, you’ll be asked to input the password and user name and the password of the host PC to connect to it. After controlling the remote computer, you can take operations just like you were sitting in front of that PC.

Part 2. Delete folder remotely with CMD

Now the remote connection must be established successfully. Now follow me to delete a folder on a remote computer with CMD on Windows 11, 10, 8, 7. Here are 2 command lines listed.

  • Use del command to delete the folder

Step 1. On the host PC, search “cmd” in the search box and then right click on the option, choose “Run as administrator”.

Run as Administrator

Step 2. Now the Command Prompt windows will be shown. Enter the command

“del /s /q \\ComputerName\c$\windows\ccmcache\FOLDERTODELETE"

For example:

del /s /q \\ComputerName\c$\windows\ccmcache\FOLDERTODELETE\MyFile"

Delete File

  • Use rmdir command to delete folder remotely

Follow the steps above and then enter “rmdir /s /q \\server\share\subfolder\FOLDERTODELETE” in Command Prompt Window. (Replace “FOLDERTODELETE” with the folder name you want to delete)

RMDIR

AnyViewer: Easily delete folder on remote computer with CMD

By following the command line list above, now you must know how to use CMD to delete a folder on a remote computer with CMD. If you meet with some problems on remote connections with Remote Desktop or you don’t want to be limited to the same LAN, here we recommend an easy-operated and high-responsive remote access software-- AnyViewer, to help you smoothly get remote access.

There are many shortcuts in AnyViewer, such as CMD, Task Manager, and Shutdown with which you can run Command Prompt with one click. More importantly, the way to connect is fairly simple. You can get remote access with one click if you log the same AnyViewer account on 2 devices. Follow me to know how AnyViewer works.

Note: To remotely control a PC from an iOS device, you can try to use AnyViewer iOS version.
Download Freeware Win 11/10/8.1/8/7
Secure Download

Step 1. On the host computer, install and run AnyViewer; click "Log in" and click "Sign up".

Log in AnyViewer

Step 2.  Filling all the necessary information to create an AnyViewer account and then you'll be logged in to AnyViewer.  

Free Edition

▣ Note:  The device will be assigned to the account automatically be assigned to the account you've logged in to. 

Step 3. On your local PC, log in to the same account as the remote PC and then go to "Device". Locate the distant computer, click it and choose "One-click control" to take full control of the PC. 

Devices

After you take over the computer remotely, you can click on “Operation”, and then click on “CMD”. After that, you can run CMD successfully and then enter the Remote-Item command line to delete the folder.

CMD

Conclusion

In this post, we list 2 ways how to use CMD delete folder on remote computer. With the command line, folder deleting could be achieved. If you run into some problems when you tend to RDP to the server or you are seeking a more convenient way to open CMD, you can also resort to AnyViewer.