Powershell: Select CSV Colums to create new CSV

My first small project with Forms. Run the script with .\modifycsv.ps1 -file .\csvfile.csv

    [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.Add_KeyDown({if ($_.KeyCode -eq "Escape") 

$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"

        foreach ($objItem in $objListbox.SelectedItems)
            {$x += $objItem}


$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"

$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:"

$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.Topmost = $True

[void] $objForm.ShowDialog()
<# FORM END --------------------------------------------------------------#>

Write-Output $csv | select-object -property $objlistbox.selecteditems | export-csv .\CSVOutput.csv -NoTypeInformation

Citrix: RestartBrokerAgent for your Service Desk

If users cannot be logged off through the Citrix Director it mostly can be solved by restarting the Broker Agent (Citrix Desktop Service) Service.
It’s a short procedure but if done fast and dirty can cause many errors (by OSI Layer 8). I wrote a really small script so everyone can easily restart the service.

get-service -ComputerName $server -name BrokerAgent | restart-service -Verbose</code>

Just give it to the Service Desk and they can now restart the BrokerAgent with .\restartbrokeragent.ps1 -server XA-Server

Powershell: Get Clipboard Content to use with your script

I wrote a little script for a Reddit user on /r/techsupport that allows him to download a youtube Video with copying the URL and just starting the script. (Download with youtube-dl https://github.com/rg3/youtube-dl/)

The Clipboard part was the most fun and I guess some people can use it.

I basically create a WinForm which I won’t show and use the System.Windows.Forms.Textbox „paste()“ function to get the text:

<code>add-type -assemblyname system.windows.forms
$form = new-object System.Windows.Forms.TextBox
$form.multiline = $true


Your Clipboard content will be in $form.Text