Powershell -NoTypeInformation: Applications and Examples

Powershell -NoTypeInformation: Applications and Examples

Powershell -NoTypeInformation: why such a big interest?

I chose to write on ‘Powershell -NoTypeInformation’ because so many people ask questions about it. In preparing to write on this topic, I was wondering why there is such a huge interest in ‘Powershell -NoTypeInformation’? 

The only answer I could come up with is because of its application in reporting. A lot of people may have had the same concern I had some time ago when I ran a PowerShell report with the Export-Csv cmdlet. When you run the Export-Csv PowerShell command it leaves some funny info on top of the csv file as shown below:

powershell-notypeinformation-3

 

Result of Export-CSV – Notice the TypeInformation on top of the file

So, what is ‘Powershell -NoTypeInformation’?

Good question! ‘Powershell -NoTypeInformation’ -actually the ‘NoTypeInformation’ bit is a PowerShell parameter found in some PowerShell commands.

If you are new to PowerShell and want to know more about PowerShell command parameters, see the article PowerShell Commands.  Most people searching for ‘Powershell -NoTypeInformation’ probably ran into trouble when they ran Export-Csv and want to know how to get rid of the annoying ‘TypeInformation’ left on top of the csv report. 

Apart from Export-Csv cmdlet, there are some other PowerShell commands (cmdlets) that have the ‘NoTypeInformation’ parameter. To find all PowerShell commands that have the ‘NoTypeInformation’ parameter, execute the command below:

Get-Command -ParameterName 'NoTypeInformation'

The above command will produce the result shown in the first figure on this page. As you see from the figure, three PowerShell cmdlets have the ‘PowerShell NoTypeInformation’ parameter: ConvertTo-Csv, ConvertTo-Xml and Export-Csv. Depending on the cmdlets on your computer, you may have more.

How do I use ‘Powershell -NoTypeInformation’?

For the remaining part of this article, I will focus on Export-Csv cmdlet. To get information about any PowerShell command, you require the Get-Command cmdlet.  If you require information about the Export-Csv, execute the command below:

Get-Help Export-Csv

The result of the command is shown below:

powershell-notypeinformation-2

 

The result of the previous command will outline the basic help information about the Export-Csv cmdlet.

To get more information about the cmdlet; including information about the ‘NoTypeInformation’ parameter, execute the command:

Get-Help Export-Csv -Full

If you wish to return examples, execute the command:

Get-Help Export-Csv -Examples

‘PowerShell -NoTypeInformation’ Examples

 Lets look at some practical examples ‘PowerShell -NoTypeInformation’. Say you want to get the list of all processes running on your computer, you could run the command below:

Get-Process | Select-Object ID, ProcessName | Export-Csv E:\Powershell-NoTypeInformation.csv

The previous command will create a csv file containing our process report. Portion of my report is shown in below:

powershell-notypeinformation-3

 

Notice that the csv header has some information you did not request for? – “#TYPE Selected.System.Diagnostics.Process” This is Get-Process TypeInfirmation. It is dropped there by the Get-Process command by default. Want proof? Enter the command below:

Get-Process | Get-Member

The result of the command is shown below: /p>

powershell-notypeinformation-4

 

Notice the “TypeName: System.Diagnostics.Process” right on top? This is where the TypeInformation on your csv report came from!

Getting rid of that unwanted information is where the ‘Powershell -NoTypeInformation’ comes in. Let’s repeat the previous command but now including the -NoTypeInformation parameter:

Get-Process | Select-Object ID, ProcessName | Export-Csv E:\Powershell-NoTypeInformation-1.csv -NoTypeInformation

Notice that the TypeInformation is gone? See Figure below for details.

powershell-notypeinformation-5

 

This is the power of ‘PowerShell -NoTypeInformation’!

References and further reading

Leave a Reply