Delete multiple folders from remote server.

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Pankaj Gairola Pankaj Gairola 2 years ago.

  • Author
    Posts
  • #20699
    Profile photo of Pankaj Gairola
    Pankaj Gairola
    Participant

    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
    Profile photo of Pankaj Gairola
    Pankaj Gairola
    Participant

    ...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
    Profile photo of Vern Anderson
    Vern Anderson
    Participant

    # 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
    Profile photo of Vern Anderson
    Vern Anderson
    Participant

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

  • #20750
    Profile photo of Pankaj Gairola
    Pankaj Gairola
    Participant

    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 )

You must be logged in to reply to this topic.