Skip to content

Test ColumnIsValid

Mateusz Czerniawski edited this page Feb 20, 2018 · 7 revisions

Test-ColumnIsValid

PPoShTools -> Test-ColumnIsValid.ps1

Synopsis

Validates a column value in a single CSV row.

Syntax

Test-ColumnIsValid [-Row] <PSObject> [-ColumnName] <String> [-NonEmpty] 
[[-NotContains] <String[]>] [[-Match] <String[]>] [[-ValidSet] <String[]>] 
[[-DateFormat] <String>] [[-LengthMax] <Int32>] [<CommonParameters>]

Description

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.

Parameters

-Row<PSObject>

CSV row (or any other PSCustomObject).

  • PipelineInput: false
  • Required: true

-ColumnName<String>

Name of the column which will be validated.

  • PipelineInput: false
  • Required: true

-NonEmpty<SwitchParameter> (default: False)

If $true, it will be asserted the column value is not empty.

  • DefaultValue: False
  • PipelineInput: false
  • Required: false

-NotContains<String[]>

If specified, it will be asserted the column value does not contain any of the specified string.

  • PipelineInput: false
  • Required: false

-Match<String[]>

If specified, it will be asserted the column value contain any of the specified string.

  • PipelineInput: false
  • Required: false

-ValidSet<String[]>

If specified, it will be asserted the column value is one of the specified string.

  • PipelineInput: false
  • Required: false

-DateFormat<String>

If specified, it will be asserted the column value can be converted to a date using specified format.

  • PipelineInput: false
  • Required: false

-LengthMax<Int32> (default: 0)

If specified, it will be asserted the column value is specified lenght.

  • DefaultValue: 0
  • PipelineInput: false
  • Required: false

Examples

Example 1

$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'