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

1 year, 1 month ago.

  • Author
  • #90574

    Points: 0
    Rank: Member


    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

    Points: 1,811
    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.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort