Add -NoHeader parameter to ConvertTo-Csv and Export-Csv cmdlets (#19108)

This commit is contained in:
Armaan Mcleod
2023-02-08 17:48:04 +05:00
committed by GitHub
parent 462f825743
commit b7e2913f6f
3 changed files with 39 additions and 9 deletions
@@ -91,6 +91,11 @@ Describe "ConvertTo-Csv" -Tags "CI" {
$result | Should -Not -Match ([regex]::Escape('#TYPE'))
}
It "Does not include headers with -NoHeader" {
$result = $testObject | ConvertTo-Csv -NoHeader
$result | Should -BeExactly '"Hello","World"'
}
It "Does not support -UseQuotes and -QuoteFields at the same time" {
{ $testObject | ConvertTo-Csv -UseQuotes Always -QuoteFields "TestFieldName" } |
Should -Throw -ErrorId "CannotSpecifyQuoteFieldsAndUseQuotes,Microsoft.PowerShell.Commands.ConvertToCsvCommand"
@@ -68,6 +68,21 @@ Describe "Export-Csv" -Tags "CI" {
$results[0] | Should -Not -Match ([regex]::Escape("#TYPE"))
}
It "Does not include headers with -NoHeader when exported and can imported with headers" {
$P1 | Export-Csv -Path $testCsv -NoHeader
$results = Get-Content -Path $testCsv
$results | Should -BeExactly '"first"'
$results = Import-Csv -Path $testCsv -Header "P1"
$results[0].P1 | Should -BeExactly "first"
}
It "Does not include headers when imported with headers and exported using -NoHeader" {
$P1 | Export-Csv -Path $testCsv
(Import-Csv -Path $testCsv) | Export-Csv -Path $testCsv -NoHeader
$results = Get-Content -Path $testCsv
$results | Should -BeExactly '"first"'
}
It "Includes type information when -IncludeTypeInformation is supplied" {
$testObject | Export-Csv -Path $testCsv -IncludeTypeInformation
$results = Get-Content -Path $testCsv