The directory is not empty

Welcome Forums General PowerShell Q&A The directory is not empty

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

 
Participant
1 year, 1 month ago.

  • Author
    Posts
  • #81224

    Participant
    Points: 0
    Rank: Member

    Hi,

    I have a script to delete the profiles folder for staff who have left

    I am calling the txt document which contains the list of profiles that need deleting

    When I run the script I get an error:

    At C:\scripts\staff leavers\deleteprofiles.ps1:1 char:50
    + ... pts\Staff leavers\profiledel.txt' | %{Remove-Item $_ -Recurse -Force}
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : WriteError: (AppData:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand
    Remove-Item : Cannot remove item \\CONTAINS THE PROFILE PATH HERE: The directory is not empty.

  • #81226

    Keymaster
    Points: 1,625
    Helping HandTeam Member
    Rank: Community Hero

    There's likely something in there it's unable to delete. Probably due to permissions.

  • #81262

    Participant
    Points: 22
    Rank: Member

    Try to run the script from an elevated shell. I'm with Don. This smells like permissions.

    • #81440

      Participant
      Points: 0
      Rank: Member

      hi,

      How would I run with an elevated shell?

  • #81289

    Participant
    Points: 22
    Rank: Member

    The other option would be lock on the folder or file which might still be open for some other application.

The topic ‘The directory is not empty’ is closed to new replies.