I want to skip the Name,Path which is the first line when it generates the CSV file. I dont know how to do so and I have no idea how to do so .
here is my code:
function Get-Path{
param($Object)
$path = $object.Name
$parent = Get-View $Object.ExtensionData.ResourcePool
while($parent){
$path = $parent.Name + "/" + $path
if($parent.Parent){
$parent = Get-View $parent.Parent
}
else{$parent = $null}
}
$path
}
Get-VM | Select Name,
@{N="Path";E={(Get-Path -Object $_) -replace "^.*?Resources"}} | Export-csv C:\izaz\test.csv -NoTypeInformation
The easiest way to export a CSV file with no header is to use ConvertTo-Csv and then use Select-Object to skip the first line:
Get-VM `
| Select Name, @{N="Path";E={(Get-Path -Object $_) -replace "^.*?Resources"}} `
| ConvertTo-Csv -NoTypeInformation `
| Select-Object -Skip 1 `
| Set-Content -Path C:\izaz\test.csv
Import-CSV -Header $StringWithAlternateHeader will set the header for the array you are importing the CSV into. It does NOT REPLACE any existing header. If you do not remove the old header from the CSV prior to import, then the old header will become a record in the array.
Example CSV:
Name,Age
Sally,15
Paul,14
$Array = Import-CSV .\example.csv
ARRAY[0] is Sally,15
ARRAY[1] is Paul,14
$Array = Import-CSV .\example.csv -Header @("Child","Age")
ARRAY[0] is Name,Age
ARRAY[1] is Sally,15
ARRAY[2] is Paul,14
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With