PowerShell: Command Line to Empty a Remote Directory

PowerShell Method
$remoteUncPath="\\FILESHERVER01\FOLDER01"
$emptyDirectory="C:\emptyDirectory"
md -Force $emptyDirectory
Remove-Item "$emptyDirectory`\*" -force -recurse -ErrorAction Continue
robocopy $emptyDirectory $remoteUncPath /mir /R:0 /W:0 /NP
DOS Command Line Method

Here is a list of commands (script) to delete all files and folder of an SMB share on QNAP

rem Set variables:
SET remoteUNC=\\NAS-SMB\DIRECTORY_TO_EMPTY\
SET password=SOMEPASSWORD
SET domain=.
SET user=ADMIN2000

rem Mount remote directory as local volume x:\
c:
net use x: %remoteUNC% /user:%domain%\%user% %password%

rem Change into newly mounted directory and perform the delete operations
x:
del /F/Q/S x:\* > NUL
for /d %x in (x:\*) do @rd /s /q "%x"
net use /delete /y x:

Leave a Reply

Your email address will not be published. Required fields are marked *