My first small project with Forms. Run the script with .\modifycsv.ps1 -file .\csvfile.csv
[CmdletBinding()] Param( [Parameter(Mandatory=$True,Position=1)] [string]$file, [parameter()] [string]$delimiter = ";" ) $csv = import-csv $file -Delimiter $delimiter $headers = $csv | get-member -membertype NoteProperty | select-object -ExpandProperty 'Name' $x = @() $headers = $csv | get-member -membertype NoteProperty | select-object -ExpandProperty 'Name' $x = @() <# FORM START ---------------------------------------------------------------------#> [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "Data Entry Form" $objForm.Size = New-Object System.Drawing.Size(300,200) $objForm.StartPosition = "CenterScreen" $objForm.KeyPreview = $True $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") { foreach ($objItem in $objListbox.SelectedItems) {$x += $objItem} $objForm.Close() } }) $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$objForm.Close()}}) $OKButton = New-Object System.Windows.Forms.Button $OKButton.Location = New-Object System.Drawing.Size(75,120) $OKButton.Size = New-Object System.Drawing.Size(75,23) $OKButton.Text = "OK" $OKButton.Add_Click( { foreach ($objItem in $objListbox.SelectedItems) {$x += $objItem} $objForm.Close() }) $objForm.Controls.Add($OKButton) $CancelButton = New-Object System.Windows.Forms.Button $CancelButton.Location = New-Object System.Drawing.Size(150,120) $CancelButton.Size = New-Object System.Drawing.Size(75,23) $CancelButton.Text = "Cancel" $CancelButton.Add_Click({$objForm.Close()}) $objForm.Controls.Add($CancelButton) $objLabel = New-Object System.Windows.Forms.Label $objLabel.Location = New-Object System.Drawing.Size(10,20) $objLabel.Size = New-Object System.Drawing.Size(280,20) $objLabel.Text = "Please make a selection from the list below:" $objForm.Controls.Add($objLabel) $objListbox = New-Object System.Windows.Forms.Listbox $objListbox.Location = New-Object System.Drawing.Size(10,40) $objListbox.Size = New-Object System.Drawing.Size(260,20) $objListbox.SelectionMode = "MultiExtended" <# DATA INPUT -------------------------------------------------------------#> write-output $headers | ForEach-Object {[void] $objListBox.Items.Add($_)} $objListbox.Height = 70 $objForm.Controls.Add($objListbox) $objForm.Topmost = $True $objForm.Add_Shown({$objForm.Activate()}) [void] $objForm.ShowDialog() <# FORM END --------------------------------------------------------------#> Write-Output $csv | select-object -property $objlistbox.selecteditems | export-csv .\CSVOutput.csv -NoTypeInformation