Public/Get-Selection.ps1
function Get-Selection { [CmdletBinding()] [OutputType([int])] Param ( [Parameter( Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0 )] $Options, [string]$Title, $Selected, [switch]$Required ) Begin { $index = 1; [string[]]$temp = @(); if ($Title) { Write-Host $Title; } } Process { foreach ($item in $Options) { if ($Selected) { $isSelected = switch ($Selected -eq $item) { $true { "x" } Default { " " } } Write-Host "($isSelected) $($index): $item" } else { Write-Host "$($index): $item" } $temp += $item; $index += 1; } } End { if ($Required) { $read = Get-Answer "Auswahl" -DefaultAnswer $Selected -AnswerRequired; } else { $read = Get-Answer "Auswahl" -DefaultAnswer $Selected; } $read = $read.Replace(',', ' '); $result = GetResult $temp $read; $result; } } function GetResult($items, $userInput) { [string[]]$result = @(); $selections = $userInput.Split(' '); foreach ($index in $selections) { $result += $items[$index - 1]; } $result; } |