locked
Remove-Item command for all window profiles RRS feed

  • Question

  • I wanting to delete all files and folders from the desktop under all window profiles. 

    I also want to keep a few .ppt that have specific names for under each profile.  Below is what I have tried and using -exclude "AppV" as an example.  Nothing works.

    Remove-item -Path C:\$users\desktop\*.* -exclude "AppV" -force -erroraction 'silentlycontinue'

    Remove-item c:\users\wcampbell\desktop\* -exclude "AppV" -force -erroraction 'silentlycontinue'

    Remove-item C:\$users\desktop -exclude "AppV" -force -erroraction 'silentlycontinue'

    Wednesday, August 28, 2019 7:54 PM

Answers

  • If this is just about excluding directories, how about:

    get-childitem c:\users\user1\desktop\* | where name -ne appv |
      remove-item -recurse -whatif

    Tuesday, September 3, 2019 6:06 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    • Marked as answer by Wes1026 Friday, September 6, 2019 12:24 PM
    Friday, September 6, 2019 11:43 AM

All replies

  • If you could do that the system would crash. There can be dozens of special profiles depending on what is installed and which OS you are targeting.

    I recommend that you learn more about Windows, Windows accounts and account profiles before pursuing this further,

    You can use WMI to correctly delete profiles.

    Search for "Win32_UserPorfile delete".


    \_(ツ)_/

    Wednesday, August 28, 2019 8:34 PM
  • JRV, I am not wanting to delete all window profiles, I just want to delete all folders and files on everyone's desktop.  I would put this in the startup folder or task scheduler.  I have about 400 clinical PC's that I need to make sure that no HIPPA data is getting saved on the desktop.

    Tuesday, September 3, 2019 12:54 PM
  • Set Group Policy to protectthe desktop so that no changes can be made.

    Use Win32_UserPorfile to find all user profile paths and use that to delete the desktop files.  By default you will not have permission to access these profiles.


    \_(ツ)_/

    Tuesday, September 3, 2019 5:02 PM
  • If this is just about excluding directories, how about:

    get-childitem c:\users\user1\desktop\* | where name -ne appv |
      remove-item -recurse -whatif

    Tuesday, September 3, 2019 6:06 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    • Marked as answer by Wes1026 Friday, September 6, 2019 12:24 PM
    Friday, September 6, 2019 11:43 AM