-
Book Overview & Buying
-
Table Of Contents
Instant Windows PowerShell Guide
By :
Here, we would be learning about the different parameters of the Out-GridView CMDLET.
The Out-GridView CMDLET gets the output in a graphical form. It leverages the .NET Framework to construct an output window, so the .NET Framework is mandatorily required to deal with the Out-GridView CMDLET.
Try executing the following lines of code.
The following command statement generates the output window along with all the services that are running, and we can select multiple service instances to stop them from having further pipeline executions:
PS C :\> Get-Service | Out-GridView –PassThru | Stop-Service
The following command creates an output window popup with "Process List" as the header:
PS C :\> Get-Process | Out-GridView -Title "Process List"

A few more parameters are introduced with the popular Out-GridView CMDLET.
-OutputMode <OutputModeOption>: By default, the Out-GridView CMDLET doesn't generate output objects except for an interactive console. Using the OutputMode parameter, you can explicitly define that you need to generate a specific number of objects as the output. It has three acceptable values as follows:
None: This is the default option and it doesn't generate any objects.
Single: This option provides only one input object to the next relevant CMDLET and passes it into the pipeline.
Multiple: This option can generate multiple input objects that can be used by the next relevant CMDLET and pass them into the pipeline. This option behaves in a way that is identical to the PassThru parameter.
-PassThru [<SwitchParameter>]: This parameter acts like the OutputMode parameter with the Multiple option. It generates multiple input objects based on what the user selects in the interactive window. These objects would be passed to the subsequent CMDLET in the pipeline.
-Title <String>: By default, the Out-GridView CMDLET generates an interactive window with a complete command statement as the title of the window. We can set the title manually using the Title parameter along with the Out-GridView CMDLET.
-Wait [<SwitchParameter>]: By default, with the execution of the Out-GridView CMDLET, the console prompt returns immediately. You can explicitly prevent the command prompt to return immediately with the Wait parameter along with the Out-GridView CMDLET.
There are a few more CMDLETs that can be useful to operate the data in an efficient way. Some are listed as follows:
The Export-Csv CMDLET exports the output data into a CSV file.
-Append [<SwitchParameter>]: By default, the Export-Csv CMDLET overwrites the output to the specified file if it is already available in the defined location. Using the Append parameter, you can restrict that behavior and allow the CSV file to append further with the output content.
This parameter adds custom methods and properties to an object.
-NotePropertyMembers <IDictionary>: With this parameter, we can explicitly provide the list of custom property names and values to be added in a hash-table format using the Add-Member CMDLET.
-NotePropertyName <String>: This parameter passes property names to the Add-Member CMDLET.
-NotePropertyValue <Object>: This parameter passes a value object to property names that are defined with the NotePropertyName parameter.
It is recommended to use NodePropertyName and NodePropertyValue together to provide custom properties with the Add-Member CMDLET.
-TypeName <String>: This parameter provides the name of the type. The type can be a class from the system namespace, and using this, you can also provide a short name for the type, for example:
PS C:\>$P = Get-ProcessPS C:\>$Job = Add-Member –InputObject $P -NotePropertyName CurrentStatus -NotePropertyValue Completed PS C:\>$Job = Add-Member CurrentStatus Completed
These command statements add the CurrentStatus property along with the value Completed to the $Job variable object.
PS C:\>$Job.CurrentStatus Completed
You can get the value of CurrentStatus using the preceding syntax.
There is one parameter named IncludeUserName introduced with the Get-Process CMDLET in Windows PowerShell 4.0:
-IncludeUserName: This parameter includes a new column as UserName in the standard process object output.

There is one limitation to this parameter; you can't use this along with the ComputerName parameter. If you want to do so, you need to use the following approach:
PS C:\> Invoke-Command -ScriptBlock { Get-Process -IncludeUserName } -ComputerName PSTest
The Get-FileHash CMDLET has been newly introduced in Windows PowerShell 4.0. It gets a hash code for your specified file. This CMDLET comes very handy while comparing same files at different locations using hash tags. If you are copying large files such as ISO files from one location to other, you can verify the consistency with which this happens, whether the files are copied successfully or not, using this CMDLET. We have the freedom to use various algorithms to calculate the hash. The following command statement calculates the hash using the MD5 algorithm for one PowerShell script:
PS C :\> Get-FileHash -FilePath D:\SpaceAnalyser.ps1 -Algorithm MD5 | Format-List Path : D:\SpaceAnalyser.ps1 Type : System.Security.Cryptography.MD5CryptoServiceProvider Hash : h9uUHj8CGtGnV35reUkehw==
Change the font size
Change margin width
Change background colour