Powershell.Helper.Extension.psm1
<#
.VERSION 1.0 .GUID 4ea20bcd-b174-46bc-ba48-08d10066ec5d .AUTHOR Bret Knoll .TAGS Helper utility format-NumberedList .RELEASENOTES First Version of script and first script released to Powershell script gallery. #> function isNumeric { param([object]$item) return $($item -match "^[1-9]{1}[0-9]{0,2}$") } function Format-Item{ param($item = @{}, [array]$property ) $property | foreach{ $column = $_ "$($item."$column")`t " } } <# .DESCRIPTION Format-NumberedList.ps1 formats lists in to a numbered list, allowing user to choose one or more items in the list. #> <# .Synopsis .Description .Parameter MajorVersion .Parameter Repository .Parameter Scope .Parameter Force #> function Format-OrderedList{ param( [array]$property ) begin{ if($property){ $arrayOfProperties = $property.Split(",") } $count=0; #"$count : Choose None!" $objectHash = @{"$count" = "DoNothing"} $formattedTable = @() } process{ $count++ if(!$arrayOfProperties){ $propertyList = $_.PSStandardMembers.DefaultDisplayPropertySet.Value # | Get-Member PSStandardMembers -Force $arrayOfProperties = $propertyList.ReferencedPropertyNames } #@{Name="Item"; Expression = {$count}} $item = $_ | select -Property $arrayOfProperties $formattedTable = $formattedTable + "$count :`t$(Format-Item -item $item -property $arrayOfProperties )" #write-host "$count : $($_ | foreach{ $rowItem = $_; $value = ($rowItem | select -first 1 -Property Name); $value })" $objectHash.Add("$count", $_) } end{ $formattedTable | Out-Host Write-host -BackgroundColor Black "`tChoose an item by #"; $listOfItems = @(); $item="0" while($item){ $item = read-host "[$($listOfItems.length)] " if(isNumeric -item $item){ #write-host $item $listOfItems = $listOfItems + $item } } $listOfItems | foreach{ $objectHash["$($_)"] } } } |