Skip to content

Uinstall-PSResource on OneDrive Error: Access to the path is denied #1793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
BohrenAn opened this issue Feb 15, 2025 · 9 comments
Open
3 tasks done

Uinstall-PSResource on OneDrive Error: Access to the path is denied #1793

BohrenAn opened this issue Feb 15, 2025 · 9 comments

Comments

@BohrenAn
Copy link

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

Hi All,

I am using Windows 11 (2024H2 26100.3194). My Document Folder is Redirected to Onedrive.
I am using Onedrive Build 25.015.0126.0002 (64-bit)
I am using PowerShell 7.5.0 and Microsoft.PowerShell.PSResourceGet 1.1.0

I regularly have Errors when uninstalling PowerShell Modules

Install the Module works fine
Install-PSResource -Name ExchangeOnlineManagement -Version 3.7.0 -Scope CurrentUser

Uninstalling the Module throws: Acces to the path is denied
Uninstall-PSResource -Name ExchangeOnlineManagement -Scope CurrentUser -SkipDependencyCheck
Uninstall-PSResource: Parent directory 'C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0' could not be deleted: Access to the path '\?\C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\en-US' is denied

Result:
All the Files are deleted, but the Folder Structure is still there

Get-ChildItem -Path "C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement" -Recurse | ft PSPath

PSPath

Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\en-US
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netCore
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netFramework
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netCore\ref
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netCore\runtimes
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netCore\runtimes\win-arm64
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netCore\runtimes\win-x64
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netCore\runtimes\win-x86
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netCore\runtimes\win-arm64\native
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netCore\runtimes\win-x64\native
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netCore\runtimes\win-x86\native
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netFramework\ref
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netFramework\runtimes
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netFramework\runtimes\win-arm64
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netFramework\runtimes\win-x64
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netFramework\runtimes\win-x86
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netFramework\runtimes\win-arm64\native
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netFramework\runtimes\win-x64\native
Microsoft.PowerShell.Core\FileSystem::C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\netFramework\runtimes\win-x86\native

Expected behavior

Uninstall-PSResource -Name ExchangeOnlineManagement -Scope CurrentUser -SkipDependencyCheck

Will uninstall the Module and delete the Folders of the Module

Actual behavior

Uninstall-PSResource -Name ExchangeOnlineManagement -Scope CurrentUser -SkipDependencyCheck

throws Acces to the path is denied and Folders are not deleted

Error details

get-error

Exception             :
    Type    : System.ArgumentException
    Message : Parent directory 'C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0' could not be deleted: Access to the path
'\\?\C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement\3.7.0\en-US' is denied.
    HResult : -2147024809
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.UninstallPSResource
CategoryInfo          : PermissionDenied: (Microsoft.PowerShel…UninstallPSResource:UninstallPSResource) [Uninstall-PSResource], ArgumentException
FullyQualifiedErrorId : ErrorDeletingDirectory,Microsoft.PowerShell.PSResourceGet.Cmdlets.UninstallPSResource
InvocationInfo        :
    MyCommand        : Uninstall-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 9
    Line             : Uninstall-PSResource -Name ExchangeOnlineManagement -Scope CurrentUser -SkipDependencyCheck
    Statement        : Uninstall-PSResource -Name ExchangeOnlineManagement -Scope CurrentUser -SkipDependencyCheck
    PositionMessage  : At line:1 char:1
                       + Uninstall-PSResource -Name ExchangeOnlineManagement -Scope CurrentUse …
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Uninstall-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
      0
      1

Environment data

Get-Module Microsoft.PowerShell.PSResourceGet; $PSVersionTable

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     1.1.0                 Microsoft.PowerShell.PSResourceGet  {Compress-PSResource, Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository…}

Key   : PSVersion
Value : 7.5.0
Name  : PSVersion


Key   : PSEdition
Value : Core
Name  : PSEdition


Key   : GitCommitId
Value : 7.5.0
Name  : GitCommitId


Key   : OS
Value : Microsoft Windows 10.0.26100
Name  : OS


Key   : Platform
Value : Win32NT
Name  : Platform


Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0…}
Name  : PSCompatibleVersions


Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion


Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion


Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion

Visuals

Uninstall-PSResource -Name ExchangeOnlineManagement -Scope CurrentUser -SkipDependencyCheck
Image

Get-ChildItem -Path "C:\Users\a.bohren\OneDrive - Icewolf\Dokumente\PowerShell\Modules\ExchangeOnlineManagement" -Recurse | ft PSPath
Image

Tried to figure out with Sysinternals ProcessMonitor
Image

@nogaff
Copy link

nogaff commented Feb 18, 2025

I've just encountered the exact same issue in both PowerShell 7.4.6 and Windows PowerShell 5.1, using Microsoft.PowerShell.PSResourceGet 1.1.0.

With PowerShell it specifically complains about access being denied to subdirectories of the module being uninstalled, but I've found that if you manually delete any subdirectories before running the uninstall command, (just leaving behind the files in the module's root), then the command actually seems to succeed.

However, with Windows PowerShell it more generically complains about the module's root directory not being empty, and even if you manually delete the subdirectories before running the uninstall command, it still fails.

I've also tried running the command as Administrator and that makes no difference.

@BohrenAn
Copy link
Author

I would say, that this did allready happen with Microsoft.PowerShell.PSResourceGet 1.0.6 and i hoped it would be fixed with Microsoft.PowerShell.PSResourceGet 1.1.0.

@BohrenAn
Copy link
Author

BohrenAn commented Mar 7, 2025

The same still happens with Microsoft.PowerShell.PSResourceGet 1.1.1

@site-speed
Copy link

I have the same issue as well (with Microsoft.PowerShell.PSResourceGet 1.1.1)
previously used to work OK - I think it started with version 1.0.6 or 1.0.5 - I don't recall exactly

the same thing happened with PowerShellGet and there was fixed in v 3.0.0-beta-19

@site-speed
Copy link

I have the same issue as well (with Microsoft.PowerShell.PSResourceGet 1.1.1) previously used to work OK - I think it started with version 1.0.6 or 1.0.5 - I don't recall exactly

the same thing happened with PowerShellGet and there was fixed in v 3.0.0-beta-19

Also unable to catch this exception - so can't really handle it nicely 😢

@BohrenAn
Copy link
Author

Any updates here @SydneyhSmith ?

@SydneyhSmith
Copy link
Collaborator

We are looking into debugging it-- will put in our upcoming quality sprint

@BohrenAn
Copy link
Author

BohrenAn commented May 6, 2025

Great to hear that. Thank you @SydneyhSmith

@site-speed
Copy link

site-speed commented May 6, 2025

In case it helps:
I'm currently working around this issue with code along these lines:

try {

    Uninstall-PSResource $oldResource -SkipDependencyCheck -ErrorAction Stop

}

catch [System.ArgumentException] {

    $FullyQualifiedErrorId = $error[0].FullyQualifiedErrorId

    if ($FullyQualifiedErrorId -eq "ErrorDeletingDirectory,Microsoft.PowerShell.PSResourceGet.Cmdlets.UninstallPSResource") {

        $resourceDir = Join-Path -Path (Split-Path -Path $PROFILE -Parent) -ChildPath "Modules"

        $resourcePath = Join-Path -Path (Join-Path -Path $resourceDir -ChildPath $resource.Name) -ChildPath $oldResource.Version

        Write-Host -ForegroundColor Red "Uninstall failed - directly delete delete $resourcePath"        

        Remove-Item -Path $resourcePath -Recurse -Force

    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants