Tag Archives: TotalCount

Get-Content

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] [-Include <string[]>] [-ReadCount <Int64>] [-TotalCount <Int64>] [-UseTransaction] [<CommonParameters>]

DESCRIPTION
    The Get-Content cmdlet gets the content of the item at the location specified by the path, such as the text in a file. It reads the content one line at a time and returns an object for each line.

PARAMETERS
    -Credential <PSCredential>
        Specifies a user account that has permission to perform this action. The default is the current user.

        Type a user name, such as “User01” or “Domain01\User01”, or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.

        This parameter is not supported by any providers that are installed with Windows PowerShell.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Exclude <string[]>
        Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

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

    -Filter <string>
        Specifies a filter in the provider’s format or language. The value of this parameter qualifies the Path parameter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved.

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

    -Force [<SwitchParameter>]
        Overrides restrictions that prevent the command from succeeding, just so the changes do not compromise security. For example, Force will override the read-only attribute or create directories to complete a file path, but it will not attempt to change file permissions.

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

    -Include <string[]>
        Retrieves only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

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

    -LiteralPath <string[]>
        Specifies the path to an item. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Path <string[]>
        Specifies the path to an item. Get-Content retrieves the content of the item. Wildcards are permitted. The parameter name (“Path” or “FilePath”) is optional.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -ReadCount <Int64>
        Specifies how many lines of content are sent through the pipeline at a time. The default value is 1. A value of 0 (zero) sends all of the content at one time.

        This parameter does not change the content displayed, but it does affect the time it takes to display the content. As the value of ReadCount increases, the time it takes to return the first line increases, but the total time for the operation decreases. This can make a perceptible difference in very large items.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -TotalCount <Int64>
        Specifies how many lines of content are retrieved. The default is -1 (all lines).

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -UseTransaction [<SwitchParameter>]
        Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_transactions.

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

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        You cannot pipe input to Get-Content.

OUTPUTS
    Object
        Get-Content returns objects that represent the content that it gets. The object type depends on the content type.

NOTES

        You can also refer to Get-Content by its built-in Aliases, “cat”, “type” and “gc”. For more information, see about_aliases.

        The Get-Content cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, type “Get-PSProvider“. For more information, see about_providers.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-Content -Path C:\Chapters\chapter1.txt

    Description
    ———–
    This command displays the content of the Chapter1.txt file on the console. It uses the Path parameter to specify the name of the item. Get-Content actually passes the content down the pipeline, but because there are no other pipeline elements, the content is formatted and displayed on the console.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-Content c:\Logs\Log060912.txt -TotalCount 50 | Set-Content sample.txt

    Description
    ———–
    This command gets the first 50 lines of the Log060912.txt file and stores them in the sample.txt file. The command uses the Get-Content cmdlet to get the text in the file. (The name of Path parameter, which is optional, is omitted.) The TotalCount parameter limits the retrieval to the first 50 lines. The pipeline operator (|) sends the result to Set-Content, which places it in the sample.txt file.

    ————————– EXAMPLE 3 ————————–

    C:\PS>(Get-Content cmdlets.txt -TotalCount 5)[-1]

    Description
    ———–
    This command gets the fifth line of the Cmdlets.txt text file. It uses the TotalCount parameter to get the first five lines and then uses array notation to get the last line (indicated by “-1”) of the resulting set.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113310
    about_providers
    Add-Content
    Set-Content
    Clear-Content

Get-Command

NAME
    Get-Command

SYNOPSIS
    Gets basic information about cmdlets and other elements of Windows PowerShell commands.

SYNTAX
    Get-Command [[-Name] <string[]>] [-CommandType {Alias | Function | Filter | Cmdlet | ExternalScript | Application | Script | All}] [[-ArgumentList] <Object[]>] [-Module <string[]>] [-Syntax] [-TotalCount <int>] [<CommonParameters>]

    Get-Command [-Noun <string[]>] [-Verb <string[]>] [[-ArgumentList] <Object[]>] [-Module <string[]>] [-Syntax] [-TotalCount <int>] [<CommonParameters>]

DESCRIPTION
    The Get-Command cmdlet gets basic information about cmdlets and other elements of Windows PowerShell commands in the session, such as Aliases, Functions, filters, scripts, and applications.

    Get-Command gets its data directly from the code of a cmdlet, Function, script, or Alias, unlike Get-Help, which gets its information from help topic files.

    Without parameters, “Get-Command” gets all of the cmdlets and Functions in the current session. “Get-Command *” gets all Windows PowerShell elements and all of the non-Windows-PowerShell files in the Path Environment Variable ($env:path). It groups the files in the “Application” command type.

    You can use the Module parameter of Get-Command to find the commands that were added to the session by adding a Windows PowerShell snap-in or importing a module.

PARAMETERS
    -ArgumentList <Object[]>
        Gets information about a cmdlet or Function when it is used with the specified parameters (“arguments”), such as a path. The Alias for ArgumentList is Args.

        To detect parameters that are added to a cmdlet when it is used with a particular provider, set the value of ArgumentList to a path in the provider drive, such as “HKML\Software” or “cert:\my”.

        Required?                    false
        Position?                    2
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -CommandType <CommandTypes>
        Gets only the specified types of commands. Use “CommandType” or its Alias, “Type”. By default, Get-Command gets cmdlets and Functions.

        Valid values are:
        — Alias: All Windows PowerShell Aliases in the current session.

        — All: All command types. It is the equivalent of “Get-Command *”.

        — Application: All non-Windows-PowerShell files in paths listed in the Path Environment Variable ($env:path), including .txt, .exe, and .dll files.

        — Cmdlet: The cmdlets in the current session. “Cmdlet” is the default.

        — ExternalScript: All .ps1 files in the paths listed in the Path Environment Variable ($env:path).

        — Filter and Function: All Windows PowerShell Functions.

        — Script: Script blocks in the current session.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Module <string[]>
        Gets the commands that came from the specified modules or snap-ins. Enter the names of modules or snap-ins, or enter snap-in or module objects.

        You can refer to this parameter by its name, Module, or by its Alias, PSSnapin. The parameter name that you choose has no effect on the command or its output.

        This parameter takes string values, but you can also supply a PSModuleInfo or PSSnapinInfo object, such as the objects that Get-Module, Get-PSSnapin, and Import-PSSession return.

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Name <string[]>
        Gets information only about the cmdlets or command elements with the specified name. <String> represents all or part of the name of the cmdlet or command element. Wildcards are permitted.

        To list commands with the same name in execution order, type the command name without wildcard characters. For more information, see the Notes section.

        Required?                    false
        Position?                    1
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -Noun <string[]>
        Gets cmdlets and Functions with names that include the specified noun. <String> represents one or more nouns or noun patterns, such as “process” or “*item*”. Wildcards are permitted.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Syntax [<SwitchParameter>]
        Gets only specified data about the command element.
                 * For Aliases, retrieves the standard name.
                 * For cmdlets, retrieves the syntax.
                 * For Functions and filters, retrieves the Function definition.
                 * For scripts and applications (files), retrieves the path and filename.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -TotalCount <int>
        Gets only the specified number of command elements. You can use this parameter to limit the output of a command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Verb <string[]>
        Gets information about cmdlets and Functions with names that include the specified verb. <String> represents one or more verbs or verb patterns, such as “remove” or *et”. Wildcards are permitted.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.String
        You can pipe a “Name”, “Command”, and “Verb” noun-property specified, or a string object to Get-Command.

OUTPUTS
    Object
        The type of object returned depends on the type of command element retrieved. For example, Get-Command on a cmdlet retrieves a CmdletInfo object, while Get-Command on a DLL retrieves an ApplicationInfo object.

NOTES

        Without parameters, “Get-Command” gets information about the Windows PowerShell cmdlets and Functions. Use the parameters to qualify the elements retrieved.

        Unlike Get-Help, which displays the contents of XML-based help topic files, Get-Command gets its cmdlet information directly from the cmdlet code in the system.

        Get-Command returns the commands in alphabetical order. When the session contains more than one command with the same name, Get-Command returns the commands in execution order. The first command that is listed is the command that runs when you type the command name without qualification. For more information, see about_command_precedence.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-Command

    Description
    ———–
    This command gets information about all of the Windows PowerShell cmdlets and Functions.

    The default display lists the command type (“Cmdlet” or “Function” or “Filter”), the name of the cmdlet or Function, and the syntax or Function definition.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-Command -Verb set | Format-List

    Description
    ———–
    This command gets information about all of the cmdlets and Functions with the verb “set”, and it displays some of that information in a list.

    The list format includes fields that are omitted from the table display, including the complete syntax. To display all fields (all properties of the object), type “Get-Command -Verb set | Format-List *”.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Get-Command -type cmdlet | Sort-Object noun | Format-Table -group noun

    Description
    ———–
    This command retrieves all of the cmdlets, sorts them alphabetically by the noun in the cmdlet name, and then displays them in noun-based
    groups. This display can help you find the cmdlets for a task.

    By default, Get-Command displays items in the order in which the system discovers them, which is also the order in which they are selected to run when a run command is ambiguous.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Get-Command -Module Microsoft.PowerShell.Security, TestModule

    Description
    ———–
    This command gets the commands in the Microsoft.PowerShell.Security snap-in and the Test-Module module.

    The Module parameter gets commands that were added by importing modules or adding Windows PowerShell snap-ins.

    ————————– EXAMPLE 5 ————————–

    C:\PS>Get-Command Get-ChildItem -args cert: -Syntax

    Description
    ———–
    This command retrieves information about the Get-ChildItem cmdlet when Get-ChildItem is used with the Windows PowerShell Certificate provider.

    When you compare the syntax displayed in the output with the syntax that is displayed when you omit the Args (ArgumentList) parameter, you’ll see that the Certificate provider dynamically adds a parameter, CodeSigningCert, to the Get-ChildItem cmdlet.

    ————————– EXAMPLE 6 ————————–

    C:\PS>(Get-Command Get-ChildItem -ArgumentList cert:).parametersets[0].parameters | Where-Object { $_.IsDynamic }

    Description
    ———–
    This command retrieves only parameters that are added to the Get-ChildItem cmdlet dynamically when it is used with the Windows PowerShell Certificate provider. This is an alternative to the method used in the previous example.

    In this command, the “Get-Command Get-ChildItem -ArgumentList cert:” is processed first. It requests information from Get-Command about the Get-ChildItem cmdlet when it is used with the Certificate provider. The “.parametersets[0]” selects the first parameter set (set 0) of “Get-ChildItem -ArgumentList cert:” and “.parameters” selects the parameters in that parameter set. The resulting parameters are piped to the Where-Object cmdlet to test each parameter (“$_.”) by using the IsDynamic property. To find the properties of the objects in a command, use Get-Member.

    ————————– EXAMPLE 7 ————————–

    C:\PS>Get-Command *

    Description
    ———–
    This command gets information about the Windows PowerShell cmdlets, Functions, filters, scripts, and Aliases in the current console.

    It also gets information about all of the files in the paths of the Path Environment Variable ($env:path). It returns an ApplicationInfo object (System.Management.Automation.ApplicationInfo) for each file, not a FileInfo object (System.IO.FileInfo).

    ————————– EXAMPLE 8 ————————–

    C:\PS>Get-Command | Where-Object {$_.definition -like “*first*”}

    CommandType     Name                        Definition
    ———–     —-                        ———
    Cmdlet         Select-Object             Select-Object [[-Property]

    Description
    ———–
    This command finds a cmdlet or Function based on the name of one of its parameters. You can use this command to identify a cmdlet or Function when all that you can recall is the name of one of its parameters.

    In this case, you recall that one of the cmdlets or Functions has a First parameter that gets the first “n” objects in a list, but you cannot remember which cmdlet it is.

    This command uses the Get-Command cmdlet to get a CmdletInfo object representing each of the cmdlets and Functions in the session. The CmdletInfo object has a Definition property that contains the syntax of the cmdlet or Function, which includes its parameters.

    The command uses a pipeline operator (|) to pass the CmdletInfo object to the Where-Object cmdlet, which examines the definition (syntax) of each object ($_) for a value that includes “first”.

    The result shows that the First parameter belongs to the Select-Object cmdlet.

    ————————– EXAMPLE 9 ————————–

    C:\PS>Get-Command dir | Format-List

    Name             : dir
    CommandType     : Alias
    Definition        : Get-ChildItem
    ReferencedCommand : Get-ChildItem
    ResolvedCommand : Get-ChildItem

    Description
    ———–
    This example shows how to use the Get-Command cmdlet with an Alias. Although it is typically used on cmdlets, Get-Command also displays information about the code in scripts, Functions, Aliases, and executable files.

    This command displays the “dir” Alias in the current console. The command pipes the result to the Format-List cmdlets.

    ————————– EXAMPLE 10 ————————–

    C:\PS>Get-Command notepad

    CommandType     Name         Definition
    ———–     —-         ———-
    Application     notepad.exe    C:\WINDOWS\system32\notepad.exe
    Application     NOTEPAD.EXE    C:\WINDOWS\NOTEPAD.EXE

    Description
    ———–
    This example shows how to use Get-Command to determine which command Windows PowerShell runs when it has access to multiple commands with the same name. When you use the Name parameter without wildcard characters, Get-Command lists the commands with that name in execution precedence order.

    This command shows which Notepad program Windows PowerShell runs when you type “Notepad” without a fully qualified path. The command uses the Name parameter without wildcard characters.

    The sample output shows the Notepad commands in the current console. It indicates that Windows PowerShell will run the instance of Notepad.exe in the C:\Windows\System32 directory.

    ————————– EXAMPLE 11 ————————–

    C:\PS>(Get-Command Get-Date).pssnapin

    C:\PS> (Get-Command remove-gpo).module

    Description
    ———–
    These commands show how to find the snap-in or module from which a particular cmdlet originated.

    The first command uses the PSSnapin property of the CmdletInfo object to find the snap-in that added the Get-Date cmdlet.

    The second command uses the Module property of the CmdletInfo object to find the module that added the Remove-GPO cmdlet.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113309
    about_command_precedence
    Get-Help
    Get-PSDrive
    Get-Member
    Import-PSSession
    Export-PSSession