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

Hyper-V: Attach a New Virtual Disk

$vmName='TestVm' $storageLocation='\\FILESERVER06\SHAREXOXO' $newDiskSize='100GB' $dynamic=$true function createNewDisk{ param( $vmName, $storageLocation, $newDiskSize='100GB', $dynamic=$true ) $ErrorActionPreference='stop' try{ write-host…

Random Notes about WSUS

#Install the PowerShell Windows Update module $checkModule=Get-Module -ListAvailable -Name PSWindowsUpdate if(!($checkModule)){ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #…

HAProxy Example for SSH & OpenVNP forwarding

# Source: https://limbenjamin.com/articles/running-https-ssh-vpn-on-port-443.html   global tune.ssl.default-dh-param 2048   defaults timeout connect 5000 timeout client 50000 timeout…