Powershell: Service Desk ICT tool (GUI)

Hey You

I hope you had an awesome weekend. I sure did. This weekend the Workplace Dudes (our podcast) had an awesome dinner. Last week we had a podcast with Jan Bakker about his self service tool.

While we were eating steak (I LOVE STEAK) we talked about automating stuff and that reminded me about a Powershell script I wrote for a client. Let me give you a quick scenario

Scenario

The ServiceDesk at this client were members of the Domain Admins AD group with their normal account which is very dangerous. Not only are they member of that group (which they don’t need) but they were also member with their normal account and not with their own elevated administrator account (but they did had one).

Why this is dangerous will be another article.

Because this is very dangerous I removed their account from the Domain Admins group but suddenly they couldn’t do much (big surprise right?). To make their live a little bit easier I created a GUI:

One Click action

Buttons… buttons… and more buttons

The idea of the GUI is that they can start any application with a single click. When they start the GUI with elevated rights (their own admin account) the app will start with elevated rights.

I had some time so I added a password generator.

Disclaimer

I am no Powershell master nor do I claim to be one. I am a work in progress. I know there might be a million better ways to do this but this is the way I did it.

I am not going into detail on how to start the GUI with admin rights because there are a lot of articles that explain how to do that but I did not find a lot of articles that explains on how to create a nice Service Desk Tool GUI. 

So… Here it is. Don’t laugh too hard though.

#Load System Windows Forms (PreReqs)
[reflection.assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null

#Here I define the GUI, the title above and the size
$guiForm = New-Object System.Windows.Forms.Form
$guiForm.Text = "ServiceDesk ICT Tool"
$guiForm.Size = New-Object System.Drawing.Size (380,410)

#Here I define another title (which isn't necessary)
$guiLabel = New-Object System.Windows.Forms.Label
$guiLabel.Location = New-Object System.Drawing.Size (10,10)
$guiLabel.Size = New-Object System.Drawing.Size (400,30)
$guiLabel.Text = "ServiceDesk ICT Tool"
$guiLabel.Font = New-Object System.Drawing.Font ("Verdana",9)

#CMD button
$selectCMD = New-Object System.Windows.Forms.Button
$selectCMD.Size = New-Object System.Drawing.Size (150,40)
$selectCMD.Text = 'CMD'
$selectCMD.Location = '10,50'
$selectCMD.Add_Click({
    Start-Process cmd.exe
    }
)

#Powershell button
$selectPowershell = New-Object System.Windows.Forms.Button
$selectPowerShell.Size = New-Object System.Drawing.Size(150,40)
$selectPowershell.Text = 'PowerShell'
$selectPowershell.Location = '10,100'
$selectPowershell.Add_Click({
    Start-Process powershell.exe
    }
)

#Powershell_ISE button
$selectPowershell_ISE = New-Object System.Windows.Forms.Button
$selectPowershell_ISE.Size = New-Object System.Drawing.Size(150,40)
$selectPowershell_ISE.Text = 'PowerShell ISE'
$selectPowershell_ISE.Location = '10,150'
$selectPowershell_ISE.Add_Click({
    Start-Process powershell_ISE.exe
    }
)

#AD button
$selectAD = New-Object System.Windows.Forms.Button
$selectAD.Size = New-Object System.Drawing.Size(150,40)
$selectAD.Text = 'Active Directory'
$selectAD.Location = '10,200'
$selectAD.Add_Click({
    Start-Process dsa.msc
    }
)

#Remote Tool button
$selectDameWare = New-Object System.Windows.Forms.Button
$selectDameWare.Size = New-Object System.Drawing.Size(150,40)
$selectDameWare.Text = 'Remote Tool'
$selectDameWare.Location = '200,150'
$selectDameWare.Add_Click({
    Start-Process "\\ProSysTech\RemoteTool\Executable.exe"
    }
)

#MMC button
$selectMMC = New-Object System.Windows.Forms.Button
$selectMMC.Size = New-Object System.Drawing.Size(150,40)
$selectMMC.Text = 'MMC'
$selectMMC.Location = '200,50'
$selectMMC.Add_Click({
    Start-Process "mmc.exe"
    }
)

#Server Manager button
$selectServerManager = New-Object System.Windows.Forms.Button
$selectServerManager.Size = New-Object System.Drawing.Size(150,40)
$selectServerManager.Text = 'Server Manager'
$selectServerManager.Location = '200,100'
$selectServerManager.Add_Click({
    Start-Process "servermanager.exe"
    }
)

#Active Directory Administrative Center button
$selectDSAC = New-Object System.Windows.Forms.Button
$selectDSAC.Size = New-Object System.Drawing.Size(150,40)
$selectDSAC.Text = 'AD Admin Center'
$selectDSAC.Location = '10,250'
$selectDSAC.Add_Click({
    Start-Process "dsac.exe"
    }
)

#Notepad button
$selectNotePad = New-Object System.Windows.Forms.Button
$selectNotePad.Size = New-Object System.Drawing.Size(150,40)
$selectNotePad.Text = 'Notepad'
$selectNotePad.Location = '200,200'
$selectNotePad.Add_Click({
    Start-Process "notepad.exe"
    }
)

#Password Generator
$passwordGenerator =  ("!@#$%^&*0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".tochararray() | sort {Get-Random})[0..13] -join ''

#Password Generator button
$selectPasswordGenerator = New-Object System.Windows.Forms.Button
$selectPasswordGenerator.Size = New-Object System.Drawing.Size(150,40)
$selectPasswordGenerator.Text = 'Generate Password'
$selectPasswordGenerator.Location = '200,250'
$selectPasswordGenerator.Add_Click({
    $passwordGenerator =  ("!@#$%^&*0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".tochararray() | sort {Get-Random})[0..13] -join ''
    $passwordGeneratorLabel.Text = $passwordGenerator
    }
)
#Password Generator Label
$passwordGeneratorLabel = New-Object System.Windows.Forms.Textbox
$passwordGeneratorLabel.Font = New-Object System.Drawing.Font ("Verdana",20)
$passwordGeneratorLabel.Location = New-Object System.Drawing.Size (10,300)
$passwordGeneratorLabel.Size = New-Object System.Drawing.Size (340,40)
$passwordGeneratorLabel.Text = $passwordGenerator

#Putting all labels and buttons in the GUI
$guiForm.Controls.Add($guiLabel)
$guiForm.Controls.Add($selectCMD)
$guiForm.Controls.Add($selectPowershell)
$guiForm.Controls.Add($selectPowershell_ISE)
$guiForm.Controls.Add($selectAD)
$guiForm.Controls.Add($selectDameWare)
$guiForm.Controls.Add($selectMMC)
$guiForm.Controls.Add($selectServerManager)
$guiForm.Controls.Add($selectDSAC)
$guiForm.Controls.Add($selectPasswordGenerator)
$guiForm.Controls.Add($passwordGeneratorLabel)
$guiForm.Controls.Add($selectNotePad)

#Starting the GUI
$guiForm.ShowDialog() 

Couple of things

You might think “You have Powershell in it why would you add Powershell ISE” or “You have the legacy AD why add AD Admin Center” in which I would reply…

… just… shut up…

Conclusion

The main purpose of this script/article is not to show off my awesome AWESOME tool but rather to show how GUI’s work within Powershell. There are a lot of better ways to create a ServiceDesk Tool but this is the way I did it.

Not so long ago I wrote another article about a Powershell Script I wrote on Cleaning your hard drive which might be interesting for you.

Thanks for reading.

Cheers,

Engin