Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 231085

Import Data with Extra Spaces

$
0
0

I'm running this script to input a csv and get VM data:

 

#Simplified version

$report = @()

Import-Csv -path c:\inputfile.csv -UseCulture | foreach{

$vmname = $_.vmname

$report += $vmname

}

$report | select vmname |  export-csv c:\outputfile.csv -notypeinformation -useculture

 

The problem is that if the input file has a column called VMName with no spaces AFTER the column title, everything works fine, but if there are spaces after the column title, it won't pick up the vmnames in the input file.  Every time someone different creates the input file, they may add an extra space before or after the column title, and mess up the results.

 

How can I make the import-csv statement read the column titles even if there are spaces before or after the column title?

 

Thanks!


Viewing all articles
Browse latest Browse all 231085

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>