Skip to content

Get-Content -Wait fails on WSL2 files #23964

Closed
@Josephur

Description

@Josephur

Prerequisites

Steps to reproduce

Map your WSL isntance to a drive letter.
For instance my W: drive is mapped to \wsl$\Ubuntu

Run Get-Content with the -Path and -Wait parameter to print out the text file and monitor it for changes:
Example: Get-Content -Path "W:\home\joseph\myvoipms\cron.log" -Wait

Expected behavior

Get-Content should wait for new content in the file, and print it as it comes in.

Actual behavior

Get-Content prints out the file, but then says "Get-Content: Incorrect function."

Error details

Exception             :
    Type            : System.ComponentModel.Win32Exception
    NativeErrorCode : 1
    ErrorCode       : -2147467259
    TargetSite      :
        Name          : WaitForChanges
        DeclaringType : [Microsoft.PowerShell.Commands.FileSystemContentReaderWriter]
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message         : Incorrect function.
    Source          : System.Management.Automation
    HResult         : -2147467259
    StackTrace      :
   at Microsoft.PowerShell.Commands.FileSystemContentReaderWriter.WaitForChanges(String filePath, FileMode fileMode,
FileAccess fileAccess, FileShare fileShare, Encoding fileEncoding)
   at Microsoft.PowerShell.Commands.FileSystemContentReaderWriter.ReadByLine(Boolean waitChanges, List`1 blocks,
Boolean readBackward)
   at Microsoft.PowerShell.Commands.FileSystemContentReaderWriter.Read(Int64 readCount)
   at Microsoft.PowerShell.Commands.GetContentCommand.ProcessRecord()
CategoryInfo          : InvalidOperation: (:) [Get-Content], Win32Exception
FullyQualifiedErrorId : ProviderContentReadError,Microsoft.PowerShell.Commands.GetContentCommand
InvocationInfo        :
    MyCommand        : Get-Content
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 3
    Line             : Get-Content -Path "W:\home\josephur\myvoipms\cron.log" -Wait
    Statement        : Get-Content -Path "W:\home\josephur\myvoipms\cron.log" -Wait
    PositionMessage  : At line:1 char:1
                       + Get-Content -Path "W:\home\josephur\myvoipms\cron.log" -Wait
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Get-Content
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
      0
      1

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.3
PSEdition                      Core
GitCommitId                    7.4.3
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-ExternalThe issue is caused by external component(s).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions