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

Audit Logon Successes & Failures on All Domain Controllers

Issue: In a realistic situation, InfoSec would notify DBAdmins and SysAdmins of failed logon alerts…

PowerShell: Maintaining Processes on Remote Servers

# maintainProcess.ps1 # version 0.0.1 $computernames=@( 'server1', 'server2' ) $processName='cmd' $processPath='C:\WINDOWS\system32\cmd.exe' $minutesToDefineCrashed=1 # this marker…

PowerShell: Audit Failed Logins of A User

$username='rambo' function auditLockouts($userName,$domainController,$refreshMinutes=1){ function getLockouts($domainControler){ # Requirement: # Domain Controllers Audit Group Policy has been…