How to Create A PowerShell Script to Delete Contents of Shared Folders

I have a folder that contains other shared folders ... I would like to delete the content of those shared folders. How can I create a PowerShell script to delete the contents of shared folders? Thank you for answering.

Best Answered by

Dany· Answered on Mar 10, 2023

PowerShell is one of the free command automation tools included with the Windows operating system. PowerShell is the best .NET framework-based scripting language, consisting of a diverse set of Command prompts that execute specific tasks. For the removal operation, it employs a file path. As a result, you may quickly delete directories, files, registry keys, variables, and shared folders by using the "Remove-Item" cmdlet. Here are the steps:

  • Navigate to "Control Panel" - "Security" - "Shared Folders" - "Shared Folder".
  • Remove the shared folders by selecting them.
  • Select "Remove". And a warning notice is displayed.
  • Optional: Select "Delete the data" (mounted ISO image files will not be deleted).
  • Select "Yes".

You may also make extra storage space available on your Synology NAS equipment by eliminating data from shared folders. To find shared folders, enter the Control Panel and click Privilege Settings. Then, select Remove Data because the formerly secured Network Recycle Bin has been transformed into standard shared folders.

However, data loss problems happen every day. Most people complain that they accidentally deleted some data from the shared folder. If there isn't any data backup, they need help to get any tool that recovers deleted files.

Checking your antivirus, which protects your files from deletion, resetting your system, uninstalling some third-party software, and other fast fixes will help you remove undeletable files or shared folders.

Ensure the data you're about to delete is in the target folder or file before performing a force delete. If an issue occurs, immediately stop using your computer or external device and use EaseUS Data Recovery Wizard to recover your data.


Use EaseUS Data Recovery Wizard to recover deleted or lost files easily and quickly.

Tutorials on how to recover lost, deleted, or formatted data from HDD, SSD, USB, SD card, or other storage media on Windows and Mac.

People Also Ask

How to Fix 'Windows 10 Administrator Can't Delete Unwanted Folder on USB'

How to fix 'Windows 10 administrator can't delete a folder on USB'? We will provide multiple solutions to help you resolve this problem. Keep reading and find an answer to your question!


Feb 22, 2023

Delete a File After It Is Processed with Command Lines

When the files are used by an application, they cannot be deleted. We will show you the command lines to delete a file after it is processed and tell you how to delete a file in use.


Mar 09, 2023

How to Fix Zip Folder Cannot Be Deleted on My Computer

Many reasons can cause this error, and we will provide several available plans to help you get out of this problem. Keep reading to learn the details.


Feb 22, 2023

How to Delete Files Older Than X Days in Folders and Subfolders

Are you tired of useless files on your computer yet eating up space? Then use this simple approach to delete files older than x days using File Explorer, CMD, and PowerShell. We can also assist you in recovering accidentally lost files on Windows 11/10.


Mar 10, 2023

How to Delete Batch Files of a Folder but Not Subfolders

It is possible to delete files in a folder and keep the subfolders, and you need to use command lines in Command Prompt. Learn the details by reading the following passage.


Mar 09, 2023

How to Restore Deleted Folder from Virtual Machines in Unraid

The Unraid user is periodically bothered by the virtual machines' data recovery and the virtual machines' disk folders not found issues. This article provides methods for recovering data from the disk of a virtual machine to minimize the loss of a virtual machine's disk file.


Feb 22, 2023