How to trim all cell value in Import-Csv so that binding ByPropertyName using pipeline binding never fails?

Viewed 50

I have a ModuleList.csv file below having Module Names in one column with header named Module

Module 
Microsoft.PowerShell.Archive
Microsoft.PowerShell.Diagnostics

Powershell Get-Command accepts parameter Module name as ByPropertyName

Example: help Get-Command -Parameter * 

-Module <System.String[]>
    Position?                    named
    Accept pipeline input?       True (ByPropertyName)

-Name <System.String[]>
    Position?                    0
    Accept pipeline input?       True (ByPropertyName, ByValue)

Now both command are giving error

Import-Csv F:\Temp\ModuleList.csv | Get-Command 
Import-Csv F:\Temp\ModuleList.csv | Get-Command *

enter image description here

Edit: I found the issue, In ModuleList.csv there was one space after Module at first line, so if I remove that space I get result. enter image description here

Now my question is How to trim all cell value in Import-Csv so that binding ByPropertyName using pipeline binding never fails?

0 Answers
Related