Tag Archives: Property

Format-Custom

NAME
    Format-Custom

SYNOPSIS
    Uses a customized view to format the output.

SYNTAX
    Format-Custom [[-Property] <Object[]>] [-Depth <int>] [-DisplayError] [-Expand <string>] [-Force] [-GroupBy <Object>] [-InputObject <psobject>] [-ShowError] [-View <string>] [<CommonParameters>]

DESCRIPTION
    The Format-Custom cmdlet formats the output of a command as defined in an alternate view. Format-Custom is designed to display views that are not just tables or just lists. You can use the views defined in the *format.PS1XML files in the Windows PowerShell directory, or you can create your own views in new PS1XML files and use the Update-FormatData cmdlet to add them to Windows PowerShell.

PARAMETERS
    -Depth <int>
        Specifies the number of columns in the display.

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

    -DisplayError [<SwitchParameter>]
        Displays errors at the command line.

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

    -Expand <string>
        Formats the collection object, as well as the objects in the collection. This parameter is designed to format objects that support the ICollection (System.Collections) interface. The default value is EnumOnly.

        Valid values are:
        — EnumOnly: Displays the properties of the objects in the collection.
        — CoreOnly: Displays the properties of the collection object.
        — Both: Displays the properties of the collection object and the properties of objects in the collection.

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

    -Force [<SwitchParameter>]
        Directs the cmdlet to display all of the error information. Use with the DisplayError or ShowError parameters. By default, when an error object is written to the error or display streams, only some of the error information is displayed.

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

    -GroupBy <Object>
        Formats the output in groups based on a shared property or value. Enter an expression or a property of the output.

        The value of the GroupBy parameter can be a new calculated property. To create a calculated, property, use a hash table. Valid keys are:

        — Name (or Label) <string>
        — Expression <string> or <script block>
        — FormatString <string>

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

    -InputObject <psobject>
        Specifies the objects to be formatted. Enter a Variable that contains the objects or type a command or expression that gets the objects.

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

    -Property <Object[]>
        Specifies the object properties that appear in the display and the order in which they appear. Wildcards are permitted.

        If you omit this parameter, the properties that appear in the display depend on the object being displayed. The parameter name (“Property”) is optional. You cannot use the Property and View parameters in the same command.

        The value of the Property parameter can be a new calculated property. To create a calculated property, use a hash table. Valid keys are:

        — Expression <string> or <script block>
        — Depth <int32>

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

    -ShowError [<SwitchParameter>]
        Sends errors through the pipeline.

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

    -View <string>
        Specifies the name of an alternate format or “view.” If you omit this parameter, Format-Custom uses a default custom view. You cannot use the Property and View parameters in the same command.

        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
    System.Management.Automation.PSObject
        You can pipe any object to Format-Custom

OUTPUTS
    Microsoft.PowerShell.Commands.Internal.Format
        Format-Custom returns the format objects that represent the display.

NOTES

        Format-Custom is designed to display views that are not just tables or just lists. To display an alternate table view, use Format-Table. To display an alternate list view, use Format-List.

        You can also refer to Format-Custom by its built-in Alias, “fc”. For more information, see about_aliases.

        The GroupBy parameter assumes that the objects are sorted. Before using Format-Custom to group the objects, use Sort-Object to sort them.

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

    C:\PS>Get-Command Start-Transcript | Format-Custom -View MyView

    Description
    ———–
    This command formats information about the Start-Transcript cmdlet in the format defined by the MyView view, a custom view created by the user. To run this command successfully, you must first create a new PS1XML file, define the MyView view, and then use the Update-FormatData command to add the PS1XML file to Windows PowerShell.

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

    C:\PS>Get-Process Winlogon | Format-Custom

    Description
    ———–
    This command formats information about the Winlogon process in an alternate customized view. Because the command does not use the View parameter, Format-Custom uses a default custom view to format the data.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113301

ConvertTo-Html

NAME
    ConvertTo-Html

SYNOPSIS
    Converts Microsoft .NET Framework objects into HTML that can be displayed in a Web browser.

SYNTAX
    ConvertTo-Html [[-Head] <string[]>] [[-Title] <string>] [[-Body] <string[]>] [-CssUri <Uri>] [[-Property] <Object[]>] [-As <string>] [-InputObject <psobject>] [-PostContent <string[]>] [-PreContent <string[]>] [<CommonParameters>]

    ConvertTo-Html [-Fragment] [[-Property] <Object[]>] [-As <string>] [-InputObject <psobject>] [-PostContent <string[]>] [-PreContent <string[]>] [<CommonParameters>]

DESCRIPTION
    The ConvertTo-Html cmdlet converts .NET Framework objects into HTML that can be displayed in a Web browser. You can use this cmdlet to display the output of a command in a Web page.

    You can use the parameters of ConvertTo-Html to select object properties, to specify a table or list format, to specify the HTML page title, to add text before and after the object, and to return only the table or list fragment, instead of a strict DTD page.

    When you submit multiple objects to ConvertTo-Html, Windows PowerShell creates the table (or list) based on the properties of the first object that you submit. If the remaining objects do not have one of the specified properties, the property value of that object is an empty cell. If the remaining objects have additional properties, those property values are not included in the file.

PARAMETERS
    -As <string>
        Determines whether the object is formatted as a table or a list. Valid values are TABLE and LIST. The default value is TABLE.

        The TABLE value generates an HTML table that resembles the Windows PowerShell table format. The header row displays the property names. Each table row represents an object and displays the object’s values for each property.

        The LIST value generates a two-column HTML table for each object that resembles the Windows PowerShell list format. The first column displays the property name; the second column displays the property value.

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

    -Body <string[]>
        Specifies the text to add after the opening <BODY> tag. By default, there is no text in that position.

        Required?                    false
        Position?                    4
        Default value                No text.
        Accept pipeline input?     false
        Accept wildcard characters? false

    -CssUri <Uri>
        Specifies the Uniform Resource Identifier (URI) of the cascading style sheet (CSS) that is applied to the HTML file. The URI is included in a style sheet link in the output.

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

    -Fragment [<SwitchParameter>]
        Generates only an HTML table. The HTML, HEAD, TITLE, and BODY tags are omitted.

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

    -Head <string[]>
        Specifies the content of the <HEAD> tag. The default is “<title>HTML TABLE</title>”. If you use the Head parameter, the Title parameter is ignored.

        Required?                    false
        Position?                    2
        Default value                <title>HTML TABLE</title>
        Accept pipeline input?     false
        Accept wildcard characters? false

    -InputObject <psobject>
        Specifies the objects to be represented in HTML. Enter a Variable that contains the objects or type a command or expression that gets the objects.

        If you use this parameter to submit multiple objects, such as all of the services on a computer, ConvertTo-Html creates a table that displays the properties of a collection or of an array of objects (System.Object[]). To create a table of the individual objects, use the pipeline operator to pipe the objects to ConvertTo-Html.

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

    -PostContent <string[]>
        Specifies text to add after the closing </TABLE> tag. By default, there is no text in that position.

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

    -PreContent <string[]>
        Specifies text to add before the opening <TABLE> tag. By default, there is no text in that position.

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

    -Property <Object[]>
        Includes the specified properties of the objects in the HTML.

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

    -Title <string>
        Specifies a title for the HTML file, that is, the text that appears between the <TITLE> tags.

        Required?                    false
        Position?                    3
        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
    System.Management.Automation.PSObject
        You can pipe any .NET object to ConvertTo-Html.

OUTPUTS
    System.String
        ConvertTo-Html returns series of strings that comprise valid HTML.

NOTES

        To use this cmdlet, pipe one or more objects to the cmdlet or use the InputObject parameter to specify the object. When the input consists of multiple objects, the output of these two methods is quite different.

        — When you pipe multiple objects to a cmdlet, Windows PowerShell sends the objects to the cmdlet one at a time. As a result, ConvertTo-Html creates a table that displays the individual objects. For example, if you pipe the processes on a computer to ConvertTo-Html, the resulting table displays all of the processes.

        — When you use the InputObject parameter to submit multiple objects, ConvertTo-Html receives these objects as a collection or as an array. As a result, it creates a table that displays the array and its properties, not the items in the array. For example, if you use InputObject to submit the processes on a computer to ConvertTo-Html, the resulting table displays an object array (System.Object[]) and its properties.

        To comply with the XHTML Strict DTD,the DOCTYPE tag is modified accordingly:
        (<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”     “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>)

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

    C:\PS>ConvertTo-Html -InputObject (Get-Date)

    Description
    ———–
    This command creates an HTML page that displays the properties of the current date. It uses the InputObject parameter to submit the results of a Get-Date command to the ConvertTo-Html cmdlet.

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

    C:\PS>Get-Alias | ConvertTo-Html > Aliases.htm

    C:\PS> Invoke-Item Aliases.htm

    Description
    ———–
    This command creates an HTML page that lists the Windows PowerShell Aliases in the current console.

    The command uses the Get-Alias cmdlet to get the Aliases. It uses the pipeline operator (|) to send the Aliases to the ConvertTo-Html cmdlet, which creates the HTML page.

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

    C:\PS>Get-Eventlog -logname “Windows PowerShell | ConvertTo-Html > pslog.htm

    Description
    ———–
    This command creates an HTML page called pslog.htm that displays the events in the Windows PowerShell event log on the local computer.

    It uses the Get-EventLog cmdlet to get the events in the Windows PowerShell log and then uses the pipeline operator (|) to send the events to the ConvertTo-Html cmdlet.

    The command also uses the redirection operator (>) to send the HTML code to the pslog.htm file.

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

    C:\PS>Get-Process | ConvertTo-Html -Property Name, Path, Company -Title “Process Information” > proc.htm; ii proc.htm

    Description
    ———–
    These commands create and open an HTML page that lists the name, path, and company of the processes on the local computer.

    The first command uses the Get-Process cmdlet to get objects that represent the processes running on the computer. The command uses the pipeline operator (|) to send the process objects to the ConvertTo-Html cmdlet.

    The command uses the Property parameter to select three properties of the process objects to be included in the table. The command uses the Title parameter to specify a title for the HTML page. The command also uses the redirection operator (>) to send the resulting HTML to a file named Proc.htm.

    The second command uses the Invoke-Item cmdlet (alias = ii) to open the Proc.htm in the default browser. The two commands are separated by a semicolon (;).

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

    C:\PS>Get-Service | ConvertTo-Html -CssUri “test.css”

    <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”     “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
    <html>
    <head>
    <title>HTML TABLE</title>
    <link rel=”stylesheet” type=”text/css” href=”test.css” />
    …

    Description
    ———–
    This command creates an HTML page of the service objects that the Get-Service cmdlet returns. The command uses the CssUri parameter to specify a cascading style sheet for the HTML page.

    The CssUri parameter adds an additional “<link rel=”stylesheet” type=”text/css” tag to the resulting HTML. The HREF attribute in the tag contains the name of the style sheet.

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

    C:\PS>Get-Service | ConvertTo-Html -As LIST > services.htm

    Description
    ———–
    This command creates an HTML page of the service objects that the Get-Service cmdlet returns. The command uses the As parameter to specify a list format. The redirection operator (>) sends the resulting HTML to the Services.htm file.

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

    C:\PS>Get-Date | cth -fragment

    <table>
    <colgroup>…</colgroup>
    <tr><th>DisplayHint</th><th>DateTime</th><th>Date</th><th>Day</th><th>DayOfWeek</th><th>DayOfYear</th><th>Hour</th><th>
    Kind</th><th>Millisecond</th><th>Minute</th><th>Month</th><th>Second</th><th>Ticks</th><th>TimeOfDay</th><th>Year</th><
    /tr>
    <tr><td>DateTime</td><td>Monday, May 05, 2008 10:40:04 AM</td><td>5/5/2008 12:00:00 AM</td><td>5</td><td>Monday</td><td
    >126</td><td>10</td><td>Local</td><td>123</td><td>40</td><td>5</td><td>4</td><td>633455808041237213</td><td>10:40:04.12
    37213</td><td>2008</td></tr>
    </table>

    Description
    ———–
    This command uses ConvertTo-Html to generate an HTML table of the current date. The command uses the Get-Date cmdlet to get the current date. It uses a pipeline operator (|) to send the results to the ConvertTo-Html cmdlet (aliased as “cth”).

    The ConvertTo-Html command includes the Fragment parameter, which limits the output to an HTML table. As a result, the other elements of an HTML page, such as the <HEAD> and <BODY> tags, are omitted.

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

    C:\PS>Get-Eventlog -log “Windows PowerShell” | ConvertTo-Html -Property id, level, task

    Description
    ———–
    This command uses the Get-EventLog cmdlet to get events from the “Windows PowerShell” event log.

    It uses a pipeline operator (|) to send the events to the ConvertTo-Html cmdlet, which converts the events to HTML format.

    The ConvertTo-Html command uses the Property parameter to select only the ID, Level, and Task properties of the event.

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

    C:\PS>Get-Service A* | ConvertTo-Html -Title “Windows Services: Server01” -Body (Get-Date) -pre “<P>Generated by Corporate IT</P
    >” -post “For details, contact Corporate IT.” > services.htm; ii services.htm

    Description
    ———–
    This command creates and opens a Web page that displays the services on the computer that begin with “A”. It uses the Title, Body, PreContent, and PostContent parameters of ConvertTo-Html to customize the output.

    The first part of the command uses the Get-Service cmdlet to get the services on the computer that begin with “A”. The command uses a pipeline operator (|) to send the results to the ConvertTo-Html cmdlet. The command uses a redirection operator (>) to send the output to the Services.htm file.

    A semicolon (;) ends the first command and starts a second command, which uses the Invoke-Item cmdlet (alias = “ii”) to open the Services.htm file in the default browser.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113290
    ConvertTo-Csv
    ConvertTo-Xml

Compare-Object

NAME
    Compare-Object

SYNOPSIS
    Compares two sets of objects.

SYNTAX
    Compare-Object [-ReferenceObject] <PSObject[]> [-DifferenceObject] <PSObject[]> [-CaseSensitive] [-Culture <string>] [-ExcludeDifferent] [-IncludeEqual] [-PassThru] [-Property <Object[]>] [-SyncWindow <int>] [<CommonParameters>]

DESCRIPTION
    The Compare-Object cmdlet compares two sets of objects. One set of objects is the Reference set, and the other set is the Difference set.

    The result of the comparison indicates whether a property value appeared only in the object from the Reference set (indicated by the <= symbol), only in the object from the Difference set (indicated by the => symbol) or, if the IncludeEqual parameter is specified, in both objects (indicated by the == symbol).

PARAMETERS
    -CaseSensitive [<SwitchParameter>]
        Indicates that comparisons should be case-sensitive.

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

    -Culture <string>
        Specifies the culture to use for comparisons.

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

    -DifferenceObject <PSObject[]>
        Specifies the objects that are compared to the reference objects.

        Required?                    true
        Position?                    2
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -ExcludeDifferent [<SwitchParameter>]
        Displays only the characteristics of compared objects that are equal.

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

    -IncludeEqual [<SwitchParameter>]
        Displays characteristics of compared objects that are equal. By default, only characteristics that differ between the reference and difference objects are displayed.

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

    -PassThru [<SwitchParameter>]
        Passes the objects that differed to the pipeline. By default, this cmdlet does not generate any output.

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

    -Property <Object[]>
        Specifies the properties of the reference and difference objects to compare.

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

    -ReferenceObject <PSObject[]>
        Objects used as a reference for comparison.

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

    -SyncWindow <int>
        Defines a search region in which an attempt is made to re-synchronize the order if there is no match. The default value is [Int32]::MaxValue.

        Required?                    false
        Position?                    named
        Default value                [Int32]::MaxValue
        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
    System.Management.Automation.PSObject
        You can pipe a DifferenceObject object to Compare-Object.

OUTPUTS
    None, or the objects that are different
        When you use the PassThru parameter, Compare-Object returns the objects that differed. Otherwise, this cmdlet does not generate any output.

NOTES

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

    C:\PS>Compare-Object -ReferenceObject $(Get-Content C:\test\testfile1.txt) -DifferenceObject $(Get-Content C:\test\testfile2.txt)

    Description
    ———–
    This command compares the contents of two text files. It displays only the lines that appear in one file or in the other file, not lines that appear in both files.

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

    C:\PS>Compare-Object -ReferenceObject $(Get-Content C:\Test\testfile1.txt) -DifferenceObject $(Get-Content C:\Test\testfile2.txt) -IncludeEqual

    Description
    ———–
    This command compares each line of content in two text files. It displays all lines of content from both files, indicating whether each line appears in only Textfile1.txt or Textfile2.txt or whether each line appears in both files.

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

    C:\PS>$processes_before = Get-Process

    C:\PS> notepad

    C:\PS> $processes_after = Get-Process

    C:\PS> Compare-Object -ReferenceObject $processes_before -DifferenceObject $processes_after

    Description
    ———–
    These commands compare two sets of process objects.

    The first command uses the Get-Process cmdlet to get the processes on the computer. It stores them in the $processes_before Variable.

    The second command starts Notepad.

    The third command uses the Get-Process cmdlet again and stores the resulting processes in the $processes_after Variable.

    The fourth command uses the Compare-Object cmdlet to compare the two sets of process objects. It displaysthe differences between them, which include the new instance of Notepad.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113286
    Group-Object
    Measure-Object
    Sort-Object
    ForEach-Object
    New-Object
    Select-Object
    Tee-Object
    Where-Object