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

PowerShell: Remove Virtual Machine Snapshots in VMM

Base Cmdlets: $vmmServer='SOMETHINGHERE' $vmName='VMNAMEHERE' $snapshots=Get-SCVMCheckpoint -vmmserver $vmmServer -vm $(get-scvirtualmachine $vmName) $snapshots|%{Remove-SCVMCheckpoint -VMCheckpoint $_} Automation: #…

PowerShell: Quickly Test Connectivity from a List of Sources toward a Destination on a Specific Port

# testRemotePort.ps1 $connectFrom=@' windows1 windows2 '@ $connectTo=@' \\servername\sharename '@ $testPort=445 $sources=@($connectFrom -split "`n")|%{$_.Trim()} $destinations=@($connectTo -split…

Regular Expression (RegEx) Overview

A good online tool to test your regex skills: https://regexr.com/ Syntax: 1. /pattern/flags2. New RegExp(pattern,…