none
power shell script to delete mulitple files from multiple folders RRS feed

  • Question

  • I'm trying to write a script that searches and deletes files in a particular folder:

    \\server\e$\XenProfiles7\%username%\UPM_Profile\AppData\Local\Citrix\AuthManager\Tracing

    So the folder is Tracing, but I need the script to search ALL the Tracing folders for all users (\\server\e$\XenProfiles7\%username%) then delete only all of the contents of the Tracing folders.

    Any pointers would be greatly appreciated

    Simon

    Friday, August 9, 2019 9:59 AM

All replies

  • Hi,

    with the ps command

    Get-Childitem -path "\\server\e$\XenProfiles7\" -recurse | select directory, name

    you can list all entire Directories including subdirectories in the mentioned path.

    You can use

    Get-Childitem -path "\\server\e$\XenProfiles7\" -recurse | Where-object {$_.Name -eq "Tracing"}

    to list only Folders named "Tracing" By adding | Remove-Item you can delete.

    So it would look like this:

    Get-Childitem -path "\\server\e$\XenProfiles7\" -recurse | Where-object {$_.Name -eq "Tracing"} | Remove-Item Further you can add -verbose to get the progress displayed and if you test it, you can add -confirm

    regards, pat

    Friday, August 9, 2019 12:09 PM
  • Hi,

    please discuss with PS expterts over here:

    https://social.technet.microsoft.com/Forums/en-US/home?forum=winserverpowershell

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.

    Thank you for your understanding.

    Regards,

    Daniel


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, August 12, 2019 2:58 AM
    Moderator