Powershell NoTypeInformation: Applications and Examples

Get-Command-ParameterName-NoTypeInformation
Spread the love
  • 2
    Shares

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 PowerShell 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:


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 below. 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.

Get-Command -ParameterName ‘NoTypeInformation’

Applications

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. To get more information about the Export-Csv cmdlet, execute the command below:

 Get-Help Export-Csv 

The result of the command is shown below:

powershell-notypeinformation-2
Get-Help Export-Csv

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 (how to use Export-Csv cmdlet), execute the command:

 Get-Help Export-Csv -Examples 

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 

Replace the path
E:\Powershell-NoTypeInformation.csv with a valid path

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 the 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:

powershell-notypeinformation-4
Get-Process | Get-Member

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

Tis is the power of ‘PowerShell -NoTypeInformation’!

I hope this have been helpful. Kindly leave comments below with your feedback.


References and further reading

  1. Export-Csv
  2. Using the Export-Csv Cmdlet
  3. ConvertTo-Csv
  4. ConvertTo-Xml
  5. Export-ADUsers

Spread the love
  • 2
    Shares

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

By using this website you agree to accept our Privacy Policy and Terms & Conditions