A tool set to validate CSV files for PowerShell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Public
en-US
.gitignore
BleyNo
CSVValidator.psd1
CSVValidator.psm1
CSVValidator.psproj
LICENSE.md
New Text Document.txt
README.md
Test-Module.ps1
TestFile.txt

README.md

Test-CSVHeader

SYNOPSIS

Test-CSVHeader tests a CSV file to validate all the headers defined in an array are present in the CSV file being tested.

SYNTAX

Set 1

Test-CSVHeader [-Path] <String> [-Headers] <String[]> [-DisallowHeadersWithoutRules] [<CommonParameters>]

DESCRIPTION

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.

EXAMPLES

EXAMPLE 1

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 2

Example of testing a CSV file and allowing extra headers (default behavior)

C:\PS> Test-CSVHeader -Path "C:\Test\Example.csv" -Headers @("Name","Data")

PARAMETERS

Path

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

Headers

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

DisallowHeadersWithoutRules

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

<CommonParameters>

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).

INPUTS

None

OUTPUTS

System.Management.Automation.PSCustomObject

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.

NOTES

RELATED LINKS

Generated by: PowerShell HelpWriter 2018 v2.2.41