Skip to content

Get-FileHash is leaving file open - can't remove it later #4174

@rkeithhill

Description

@rkeithhill

This issue was originally filed on the Plaster project but the problem seems to be with PowerShell Core.

Steps to reproduce

PS C:\Users\Keith> $hash = (Get-FileHash .\remove.psd1).Hash
PS C:\Users\Keith> $hash
E58204D2C5BB9057A085C00D3EEC3ED96390C52A739D4ADCCC02A1B1A4DDF1B8
PS C:\Users\Keith> Remove-Item .\remove.psd1
Remove-Item : The process cannot access the file 'C:\Users\Keith\remove.psd1' because it is being used by another
process.
At line:1 char:1
+ Remove-Item .\remove.psd1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\Users\Keith\remove.psd1:FileInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand

Expected behavior

Remove-Item should work.

Actual behavior

Remove-Item fails because apparently the execution of Get-FileHash has resulted in an open file handle on the file.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
GitCommitId                    v6.0.0-beta.3-20-g27e47f9ee1aa0592bffe17c8f979cfa6513887a4
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions