-
Notifications
You must be signed in to change notification settings - Fork 0
Test ColumnIsValid
PPoShTools -> Test-ColumnIsValid.ps1
Validates a column value in a single CSV row.
Test-ColumnIsValid [-Row] <PSObject> [-ColumnName] <String> [-NonEmpty]
[[-NotContains] <String[]>] [[-Match] <String[]>] [[-ValidSet] <String[]>]
[[-DateFormat] <String>] [[-LengthMax] <Int32>] [<CommonParameters>]
It is useful in Get-CsvData / Get-ValidationRules to validate columns read from CSV row. It returns empty array if the value is valid, or array of error messages if it's invalid.
CSV row (or any other PSCustomObject).
- PipelineInput: false
- Required: true
Name of the column which will be validated.
- PipelineInput: false
- Required: true
If $true, it will be asserted the column value is not empty.
- DefaultValue: False
- PipelineInput: false
- Required: false
If specified, it will be asserted the column value does not contain any of the specified string.
- PipelineInput: false
- Required: false
If specified, it will be asserted the column value contain any of the specified string.
- PipelineInput: false
- Required: false
If specified, it will be asserted the column value is one of the specified string.
- PipelineInput: false
- Required: false
If specified, it will be asserted the column value can be converted to a date using specified format.
- PipelineInput: false
- Required: false
If specified, it will be asserted the column value is specified lenght.
- DefaultValue: 0
- PipelineInput: false
- Required: false
$errors += Test-ColumnIsValid -Row $CsvRow -ColumnName 'Login' -NonEmpty -NotContains '?', ' '
$errors += Test-ColumnIsValid -Row $CsvRow -ColumnName 'Name' -NonEmpty -NotContains '?' $errors += Test-ColumnIsValid -Row $CsvRow -ColumnName 'StartDate' -DateFormat 'yyyy-MM-dd' $errors += Test-ColumnIsValid -Row $CsvRow -ColumnName 'Gender' -ValidSet '', 'F', 'M'