Tag Archives: Title

Out-GridView

NAME
    Out-GridView

SYNOPSIS
    Sends output to an interactive table in a separate window.

SYNTAX
    Out-GridView [-InputObject <psobject>] [-Title <string>] [<CommonParameters>]

DESCRIPTION
    The Out-GridView cmdlet sends the output from a command to a grid view window where the output is displayed in an interactive table. This feature requires Microsoft .NET Framework 3.5 with Service Pack 1.

    You can use the following features of the table to examine your data:

    — Hide, Show, and Reorder Columns: To hide, show, or reorder a column, right-click a column header and then click “Select Columns.”

    — Sort. To sort the data, click a column header. Click again to toggle from ascending to descending order.

    — Quick Filter. Use the “Filter” box at the top of the window to search the text in the table. You can search for text in a particular column, search for literals, and search for multiple words.

    — Criteria Filter. Use the “Add criteria” drop-down menu to create rules to filter the data. This is very useful for very large data sets, such as event logs.

    — Copy and paste. To copy rows of data from Out-GridView, press CTRL+C (copy). You can paste the data into any text or spreadsheet program.

    For instructions for using these features, type “Get-Help Out-GridView -full” and see “How to Use the Grid View Window Features” in the NOTES section.

PARAMETERS
    -InputObject <psobject>
        Accepts input for Out-GridView.

        When you use the InputObject parameter to send a collection (more than one) of objects to Out-GridView, Out-GridView treats the collection as one collection object, and it displays one row that represents the collection. To display the each object in the collection, use a pipeline operator (|) to send objects to Out-GridView.

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

    -Title <string>
        Specifies the text that appears in the title bar of the Out-GridView window.

        By default, the title bar displays the command that invokes Out-GridView.

        Required?                    false
        Position?                    named
        Default value                The current command
        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 send any object to Out-GridView.

OUTPUTS
    None
        Out-GridView does not return any objects.

NOTES

        NOTES FOR Out-GridView
        ———————-

        You can download the Microsoft .NET Framework 3.5 with Service Pack 1 from the Microsoft Download Center.

        Because this cmdlet requires a user interface, it does not work on Server Core installations of Windows Server.

        You cannot use a remote command to open a grid view window on a remote computer.

        The command output that you send cannot be pre-formatted, such as by using the Format-Table or Format-Wide cmdlets. To select properties, use the Select-Object cmdlet.

        Deserialized output from remote commands might not be formatted correctly in the grid view window.

        KEYBOARD SHORTCUTS FOR Out-GridView
        ———————————–

        By using the following keyboard shortcuts, you can perform many tasks quickly.

        Use this key:     To perform this action:
        ————-     —————————————————————-
        TAB             Moves the cursor from the Filter box to the Add criteria menu to the table and back.
        UP ARROW         Move up one row. Will move to column headers.
        DOWN ARROW        Move down one row.
        LEFT ARROW        In column header row, move left one column.
        RIGHT ARROW     In column header row, move right one column.
        CONTEXT MENU KEY In column header row, displays the “Select Columns” option.
        ENTER or SPACEBAR In column header row, sort column data (toggle A-Z, Z-A).

        HOW TO USE THE GRID VIEW WINDOW FEATURES
        —————————————-
        The following topics explain how to use the features of the window that Out-GridView displays.

        How to Hide, Show, and Reorder Columns
        ————————————–
        To hide or show a column:

        1. Right click any column header and click “Select Columns”.

        2. In the “Select Columns” dialog box, use the arrow keys to move the columns between the “Selected columns” to the “Available columns” boxes. Only columns in the “Selected Columns” box appear in the grid view window.

        To reorder columns:

        — Drag and drop the column into the desired location.

        – or-

        1. Right click any column header and click “Select Columns”.

        2. In the “Select Columns” dialog box, use the “Move up” and “Move down” buttons to reorder the columns. Columns at the top of the list appear to the left of columns at the bottom of the list in the grid view window.

        How to Sort Table Data
        ———————-
        — To sort the data, click a column header.
        — To change the sort order, click the column header again. Each time you click the same header, the sort order toggles between ascending to descending order. The current order is indicated by a triangle in the column header.

        How to Select Table Data
        ————————
        — To select a row, click the row or use the up or down arrow to navigate to the row.
        — To select all rows (except for the header row), press CTRL+A.
        — To select consecutive rows, press and hold the SHIFT key while clicking the rows or using the arrow keys.
        — To select nonconsecutive rows, press the CTRL key and click to add a row to the selection.
        You cannot select columns, and you cannot select the entire column header row.

        How to Copy Rows
        ———————-
        — To copy one or more rows from the table, select the rows and then press CTRL+C.
        You can paste the data into any text or spreadsheet program. You cannot copy columns or parts of rows and you cannot copy the column header row.

        How to Search in the Table (Quick Filter)
        ———————————
        Use the “Filter” box to search for data in the table. When you type in the box, only items that include the typed text appear in the table.

        — Search for text. To search for text in the table, in the “Filter” box, type the text to find.

        — Search for multiple words. To search for multiple words in the table, type the words separated by spaces. Out-GridView displays rows that include all of the words (logical AND).

        — Search for literal phrases. To search for phrases that include spaces or special characters, enclose the phrase in quotation marks. Out-GridView displays rows that include an exact match for the phrase.

        — Search in columns. To search for text in one or more columns, use the following format:

         <column>:<text> [<column>:<text>] …

            For example, to find “Net” in the DisplayName column, in the “Filter” box, type:

         displayname:net

            To find rows with “Net” in the DisplayName and Name columns, in the “Filter” box, type:

         displayname:net name:net

        — Turn off search. To display the entire table again, click the red X button in the top right corner of the “Filter” box or delete the text from the Filter box.

        Use Criteria to Filter the Table
        ——————————–
        You can use rules or “criteria” to determine which items are displayed in the table. Items appear only when they satisfy all of the criteria that you establish. The available criteria are determined by the properties of the objects displayed in the grid view window and the .NET Framework types of those properties.

        Each criterion has the following format:
        <column> <operator> <value>

        Criteria for different properties are connected by AND. Criteria for the same property are connected by OR. You cannot change the logical connectors.

        The criteria only affects the display. It does not delete items from the table.

        How to Add Criteria
        —————————
        1. To display the “Add criteria” menu button, in the upper right corner of the window, click the “Expand” arrow.
        2. Click the “Add Criteria” menu button.
        3. Click to select columns (properties). You can select one or many properties.
        4. When you are finished selecting properties, click the Add button.
        5. To cancel the additions, click Cancel.
        6. To add more criteria, click the Add Criteria button again.

        How to Edit a Criterion
        ——————–
        — To change an operator, click the blue operator value, and then click to select a different
         operator from the drop-down list.
        — To enter or change a value, type a value in the value box. If you enter a value that is not valid, a circular X icon appears. To remove it, change the value.
        — To create an OR statement, add a criteria with the same property.

        How to Delete Criteria
        ————————-
        — To delete selected criteria, click the red X beside each criterion.
        — To delete all criteria, click the “Clear All” button.

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

    C:\PS>Get-Process | Out-GridView

    Description
    ———–
    This command gets the processes running on the local computer and sends them to a grid view window.

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

    C:\PS>$p = Get-Process

    C:\PS> $p | Out-GridView

    Description
    ———–
    This command also gets the processes running on the local computer and sends them to a grid view window.

    The first command uses the Get-Process command to get the processes on the computer and then saves the process objects in the $p Variable.

    The second command uses a pipeline operator to send the $p Variable to Out-GridView.

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

    C:\PS>Get-Process | Select-Object -property name, workingset, peakworkingset | Sort-Object -property workingset -desc | Out-GridView

    Description
    ———–
    This command displays a formatted table in a grid view window.

    It uses the Get-Process cmdlet to get the processes on the computer.

    Then, it uses a pipeline operator (|) to send the process objects to the Select-Object cmdlet. The command uses the Property parameter of Select-Object to select the Name, WorkingSet, and PeakWorkingSet properties to be displayed in the table.

    Another pipeline operator sends the filtered objects to the Sort-Object cmdlet, which sorts them in descending order by the value of the WorkingSet property.

    The final part of the command uses a pipeline operator (|) to send the formatted table to Out-GridView.

    You can now use the features of the grid view to search, sort, and filter the data.

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

    C:\PS>($a = Get-ChildItem -path $pshome -recurse) | Out-GridView

    Description
    ———–
    This command saves its output in a Variable and sends it to Out-GridView.

    The command uses the Get-ChildItem cmdlet to get the files in the Windows PowerShell installation directory and its subdirectories. The path to the installation directory is saved in the $pshome automatic Variable.

    The command uses the assignment operator (=) to save the output in the $a Variable and the pipeline operator (|) to send the output to Out-GridView.
    The parentheses in the command establish the order of operations. As a result, the output from the Get-ChildItem command is saved in the $a Variable before it is sent to Out-GridView.

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

    C:\PS>Get-Process -computername Server01| ogv -Title “Processes – Server01”

    Description
    ———–
    This command displays the processes that are running on the Server01 computer in a grid view window.

    The command uses “ogv,” which is the built-in Alias for the Out-GridView cmdlet, it uses the Title parameter to specify the window title.

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

    C:\PS>Invoke-Command -ComputerName S1, S2, S3 -scriptblock {Get-Culture} | Out-GridView

    Description
    ———–
    This example shows the correct format for sending data collected from remote computers to the Out-GridView cmdlet.

    The command uses the Invoke-Command cmdlet to run a Get-Culture command on three remote computers. It uses a pipeline operator to send the data that is returned to the Out-GridView cmdlet.

    Notice that the script block that contains the commands that are run remotely does not include the Out-GridView command. If it did, the command would fail when it tried to open a grid view window on each of the remote computers.

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

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