Have the requirement wherein there are 2 outputs which we need to do a union of below expression into an Array
a) $PipelineDataset.Activities.Name
b) ([regex]::Matches((Get-Content $TempFilePath),$pattern).groups|Where-Object Name -EQ '1').Value
IF ($PipelineDataset.Activities.Name.GetType().Name -eq 'String')
{$OuterActivityNames=$PipelineDataset.Activities.Name.Split(",")}
else
{$OuterActivityNames=$PipelineDataset.Activities.Name}
$ActivitiesName= $OuterActivityNames + ([regex]::Matches((Get-Content $TempFilePath),$pattern).groups|Where-Object Name -EQ '1').Value
There are scenarios wherein sometime there is only 1 value returned for this output : $PipelineDataset.Activities.Name thereby making it as a String type. So I am using the If else activity to convert it into array. Is that the right approach ?
Also, for the union I am using + operator and in case if there is no value present for ([regex]::Matches((Get-Content $TempFilePath),$pattern).groups|Where-Object Name -EQ '1').Value , it is still appending a value in the output array. example : lets say the 1st gives 1 element and 2nd expression has no value, the length of the overall array is coming as 2.
So how to avoid it?