Delete folder ans sub folders silently

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Nithun Damodaran Nithun Damodaran 3 years, 2 months ago.

  • Author
    Posts
  • #14762
    Profile photo of Nithun Damodaran
    Nithun Damodaran
    Participant

    Is there any way to delete a folder and its sub folders silently using Remove-Item ?

    so far tried with -force and -confirm:$false but its prompting for confirmation.

  • #14763
    Profile photo of Stein Petersen
    Stein Petersen
    Participant

    Hi.

    what is the code you run?

    I have no issues running

    Remove-Item -path D:\temp\FolderToRemove -Recurse -Force

    on Win8.1/PS4.0

  • #14765
    Profile photo of Nithun Damodaran
    Nithun Damodaran
    Participant

    Hi Stein,

    Thanks for your time, below is my code

    Remove-Item -path D:\inetpub\foldertoremove -force

    I am not using -recurse as i want to delete entire thing(sub folders). Am running it on ISE and its prompting for confirmation

    please correct me if am wrong

  • #14766
    Profile photo of Stein Petersen
    Stein Petersen
    Participant

    You can test it on a different folderstructure first, but you have to use -recurse to make it remove subdirectories.
    If you read the help file for remove-item it will point to a different method in example 4.

  • #14767
    Profile photo of Nithun Damodaran
    Nithun Damodaran
    Participant

    Thanks steing, I am good with it

You must be logged in to reply to this topic.