function Test-ConfigurationDataExpressionParentheses { [CmdletBinding()] Param( [AllowNull()] [string] $Expression ) if([string]::IsNullOrWhiteSpace($Expression)){ return $true } $Depth = 0 $InString = $false for($Index = 0; $Index -lt $Expression.Length; $Index++){ $Character = $Expression[$Index] if($Character -eq "'"){ $InString = -not $InString continue } if($InString){ continue } if($Character -eq "("){ $Depth++ }elseif($Character -eq ")"){ $Depth-- if($Depth -lt 0){ return $false } } } return $Depth -eq 0 -and -not $InString }