Getting access denied error while using Remove-Item

Welcome Forums General PowerShell Q&A Getting access denied error while using Remove-Item

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
10 months, 2 weeks ago.

  • Author
    Posts
  • #90574

    Participant
    Points: 0
    Rank: Member

    Hi,

    Remove-Item "IIS:\Sites\$($getApp.SiteName)\$App\*" -Exclude "*.ttf" -Force -Recurse -ErrorAction Stop

    Trying to exclude .ttf file while deleting content in directory.Getting below error message..TTF are using by other applications.

    System.UnauthorizedAccessException: Access to the path 'MuseoForCCC-Bold.ttf' is denied.Please suggest me command to delete content in directory while exluding .ttf files.

  • #90589

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

    If another process has a lock on the file, then Windows won't allow you to delete it. You might need to pause or stop the IIS service, for example, to free up those locks.

    -Exclude probably won't work well in the IIS drive. It'd perhaps be better to do a Get-ChildItem, filter out the TTF files by using Where-Object, and pipe the remains to Remove-Item. The IIS drive is a bit of an outlier and doesn't correctly implement all of the *-Item commands' options.

The topic ‘Getting access denied error while using Remove-Item’ is closed to new replies.