Delete multiple folders from remote server.

Welcome Forums General PowerShell Q&A Delete multiple folders from remote server.

This topic contains 4 replies, has 2 voices, and was last updated by

 
Participant
4 years ago.

  • Author
    Posts
  • #20699

    Participant
    Points: 0
    Rank: Member

    Can somebody help me with the script which can delete multiple folders (around 100 to 200 folders size approx 900 GB ) from location
    (\\servername\compdata$\folersxx ) .. i am looking for something which can intitiate delete for all the folder i do not want to wait for one folder to complete then other as it will take lot of time...
    Script should check foder location first if exist delete and output in log file...

    Appriciate your help...!!

  • #20700

    Participant
    Points: 0
    Rank: Member

    ...continue

    forgot to mentiion.... want to delete specif folders that i have in notepad or excel these folder should get deleted rest should remain the same...

  • #20747

    Participant
    Points: 1
    Rank: Member

    # Remember to enter credentials that are valid for each server in your c:\servers.txt file
    $credentials = Get-Credential
    $servers = Get-Content c:\servers.txt
    foreach ($server in $servers)
    {
    $scriptsFolder = Invoke-Command -ComputerName $server -Credential $credentials -ScriptBlock {Test-Path C:\Scripts}
    if ($scriptsFolder -eq $true)
    {
    Invoke-Command -ComputerName $server -Credential $credentials -ScriptBlock {Remove-Item C:\scripts -Recurse -WhatIf}
    }
    }

  • #20748

    Participant
    Points: 1
    Rank: Member

    Remove the "whatif" when you get real serious about it!

  • #20750

    Participant
    Points: 0
    Rank: Member

    Thanks for speedy reply...

    for mutiple servers it looks good.. I will test it out today.

    ... quick question
    What if i have one server and multiple folders on one shared loation ( \\servername\companydata$ , under company data i have total 500 folders and i have to delete 100 folders in one go and get the output in TXT file )

The topic ‘Delete multiple folders from remote server.’ is closed to new replies.