1

Curiously, although the hibernation file is located in the root directory, it could not be detected by PowerShell. Apparently this is a kind of virtual file.

$Path = "$Env:SystemDrive\hiberfil.sys"

# Result $False
Test-Path -Path $Path 

# Result 0
(Get-ChildItem -Path $Path -Force).Length 

So, how can I find out the size of the hibernation file?

Sure, size can be recognized when resizing hibernation powercfg.exe /hibernate /size 50. But how to know the size without changing the size of the hibernation? Thanks

  • 2
    `(Get-ChildItem -Path $env:SystemDrive\ -Filter hiberfil.sys -Force).Length` works. I can't explain why `"$Env:SystemDrive\hiberfil.sys"` does not. It seems like a bug to me. – AdminOfThings Jan 09 '20 at 12:19

1 Answers1

2

You can do the following:

(Get-ChildItem -Path $env:SystemDrive\ -Filter hiberfil.sys -Force).Length

Unfortunately, I cannot explain why Get-ChildItem -Path $Path -Force does not work. This particular syntactical pattern works for other files that are not .sys files in that directory. I don't know if this restriction was by design or a bug.


Other querying commands can find the file without issues:

# Finds the File but doesn't return a FileInfo object
cmd /c "dir $env:systemdrive\hiberfil.sys /A:S"

# A less elegant command that retrieves the required data
[System.IO.FileInfo]::new([System.IO.Directory]::GetFiles(($env:systemdrive+'\'),'hiberfil.sys')).Length
AdminOfThings
  • 23,946
  • 4
  • 17
  • 27