Test-CSVHeader tests a CSV file to validate all the headers defined in an array are present in the CSV file being tested.
Test-CSVHeader [-Path] <String> [-Headers] <String> [-DisallowHeadersWithoutRules] [<CommonParameters>]
The function Test-CSVHeader takes a path to a CSV file as well as an array of headers to validate are present in the CSV file. The switch DisallowHeadersWithoutRules can also be used which will cause the CSV file to be marked invalid if there are extra headers in the CSV file which are not present in the Headers array.
Example of testing a CSV file and marking it as invalid if there are extra headers
C:\PS> Test-CSVHeader -Path "C:\Test\Example.csv" -Headers @("Name","Data") -DisallowHeadersWithoutRules
Example of testing a CSV file and allowing extra headers (default behavior)
C:\PS> Test-CSVHeader -Path "C:\Test\Example.csv" -Headers @("Name","Data")
The path to the CSV file to test. The path to the file is tested by a validation script to ensure the file exists before it is processed.
Type: String Parameter Sets: Set 1 Aliases: File , FilePath , csv , csvfile Required: true Position: 0 Default Value: Pipeline Input: False
An array of headers to ensure are present in the CSV file.
Type: String Parameter Sets: Set 1 Aliases: Required: true Position: 1 Default Value: Pipeline Input: False
If this switch is present, a CSV file will be considered to not be valid if it contains headers which are not present in the Headers array. If the switch is not present, then the file is considered valid if there are extra headers in the CSV file not defined by the Headers array.
Type: SwitchParameter Parameter Sets: Set 1 Aliases: Required: false Position: named Default Value: Pipeline Input: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
A custom PSObject which contains the following properties:HeadersInRules,RulesAllPresent,CSVValid,MissingHeaders. HeadersInRules is true if all of the headers in the CSV file are present in the Headers array. If there are extra headers in the CSV file, the property is false. If all of the headers defined in the Headers array are present in the CSV file, then this property is true. If RulesAllPresent is true and DisallowHeadersWithoutRules is not present then even if HeaderInRules is false CSVValid will be true. If however, DisallowHeadersWithoutRules is present and HeadersInRules is false, then the CSV file will be marked as invalid.
Generated by: PowerShell HelpWriter 2018 v2.2.41