Posted On July 26, 2019

PowerShell: Command Line to Empty a Remote Directory

kimconnect 0 comments
blog.KimConnect.com >> Codes >> 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 *

Related Post

Bash Shell: Old School Migration of ESXi Guest Virtual Machines

Step 0: Preparations Estimate file-copying duration for cut-over:- Sustained storage transfer speed using a 1GB…

Invoke T-SQL on Multiple Servers

$computersAndCredentials=@{ 'SQL01'=@{'intranet\sql01Admin'='PASSWORD'} 'SQL02'=@{'intranet\sql02Admin'='PASSWORD'} 'SQL03'=@{'intranet\sql03Admin'='PASSWORD'} 'SQL04'=@{'intranet\sql04Admin'='PASSWORD'} } $tSql=" --Update the Setting with a new value: USE…

How to Add a Replica into an Existing Availability Group using PowerShell

Overview:0. Add secondary replica to the cluster by running some commands on the availability group…