Question

While Going through Help of Get-content in Powershell V2, i couldn't find -Wait parameter. Although i can use this parameter with the same cmdlet. This is not one of commonParameters for sure.

NAME
    Get-Content

SYNOPSIS
    Gets the content of the item at the specified location.

SYNTAX
    Get-Content [-LiteralPath] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force
    ] [-Include <string[]>] [-ReadCount <Int64>] [-TotalCount <Int64>] [-UseTransaction] [<CommonParameters>]

    Get-Content [-Path] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Inc
    lude <string[]>] [-ReadCount <Int64>] [-TotalCount <Int64>] [-UseTransaction] [<CommonParameters>]

The only commandlet i could find where -Wait parameter was mentioned explicitly in Powershell V2 was Start-process

Does get-content calls Start-process under the hood? How am i able to use -Wait parameter with Get-content?

This may help in discovering other Parameters which are not mentioned in the Help, but can be used with that cmdlet. Thanks in Advance for help!

Was it helpful?

Solution 2

It looks like both 'raw' and 'wait' are dynamic parameters. And, 'wait' is using FileSystemWatcher in the background. The default time it waits for changes, seems to be 500ms.

Once, it timesout; the thread sleeps for an additional 100ms and then seeks beginning of the stream and discards buffers.

Reference: Figured it out after reading through PowerShell MVP Oisin Grehan's blog 'A trick to jump directly to a Cmdlet’s implementation in Reflector', 'Reflect-Cmdlet'.

Also, read the following question: can we see the source code for PowerShell cmdlets

OTHER TIPS

The documentation for this switch has been added in later versions of PowerShell. This is from PS 4.0.

PS > Get-Help Get-Content -Parameter wait

-Wait [<SwitchParameter>]
    Waits for the cmdlet to get the content before returning the command prompt. While waiting, Get-Content checks the
    file once each second until you interrupt it, such as by pressing CTRL+C.

    Wait is a dynamic parameter that the FileSystem provider adds to the Get-Content cmdlet. This parameter works only
    in file system drives.

    Required?                    false
    Position?                    named
    Default value                False
    Accept pipeline input?       false
    Accept wildcard characters?  false

As @sqlchow pointed out -wait is a dynamic parameter of get-content and can only be used with Filesystem providers according to documentation available Here.
i.e, If you are in registry provider, you can't use this parameter with get-content(at least in Powershell V2)

PS C:\> cd HKLM:\
PS HKLM:\> Get-Content -Wait
Get-Content : A parameter cannot be found that matches parameter name 'Wait'.

We can see that wait is not available for Registry provider.

There is a nice blog post by Ed Wilson on How to find Dynamic Paramters

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top