function Get-ChocoStateReleaseInput { <# .SYNOPSIS Returns a list of package name/version/feed objects from an unsanitized user input list of "package version"'s. #> [CmdletBinding()] [OutputType([System.Object])] Param( [Parameter(Mandatory = $true)] [string]$text ) $option = [System.StringSplitOptions]::RemoveEmptyEntries; $lines = $text.Split([Environment]::NewLine, $option); $validPackages = @(); $lines | ForEach-Object { # Cut down whitespace. $line = ($_ -replace '\s+', ' ').Trim(); $data = $line.Split(' ', $option); # Arbitrary but reasonably effective means of filtering for valid name/version text input lines. if (($data.count -eq 2) -and ($data[1] -like "*.*")) { $properties = @{ Name = $data[0]; Version = $data[1]; Feed = $null; Tags = $null; }; $pkg = New-Object -TypeName PSObject -Prop $properties; $validPackages += $pkg; } else { write-error "$_ is not a valid package name and version" } }; return $validPackages; }