r/PowerShell • • Apr 13 '20

I created a Discord bot to host Jackbox Party games for my mother

148 Upvotes

My family has been getting together for game night during the quarantine in order to keep spirits up and have a bit of social interaction. My mom liked this idea so much that she decided to start hosting additional game nights with her friends. I remoted into her machine the other day to attempt to set up streaming from her machine but quickly realized bandwidth would be a blocker for her. Seeing as I'm on gigabit, I told her to give me a few hours and I'd spin up a VM for her to host the games on a server I just finished building for home automation.

I taught her how to RDP into the virtual box and start the game/stream. I gave her two scripts to click on that did the majority of the work, but I knew that bouncing between machines was ultimately going to lead to numerous calls where I'd have to figure out what she had messed up and fix it. Instead of going through all that, I decided to just make a Discord bot from powershell.

The bot, JackBot, is more of a hybrid bot since I wanted to keep this down to a simpler project since it's just hosting games. It consists of a Discord API bot subscribed to the GameHost server in order to scrape text for the !jackbot keyword, a webhook to keep sending messages as simple as possible, and a standard Discord user for joining and streaming. It's hosted on a Windows VM and it uses powershell to monitor, fire up processes, and use key commands to control Discord and Jackbox (since neither have native integration).

So now, with a single line she can call the bot and see her options, then fire up the stream from a VM and host it on gig internet without having to much about with remoting or setting up the stream herself.

Now that it's built I've decided to give access to a few other folks in the family that may not be able to host their own games but might find enjoyment while stuck at home.

Just wanted to put the idea out there and let people know there's other ways for us to help those around us. The only cost for this project for me was a Jackbox key (which is on sale right now) to put on a secondary Steam account so it didn't interfere with my personal Steam account.

EDIT: I've got the code loaded up to GitHub with a "quick" version of the how-to setup. It's fairly involved but nothing is particularly difficult.

JackBot on GitHub


r/PowerShell • • Jul 28 '19

Script Sharing PowerShell Tutorial Mini-Course (Free)

Thumbnail
adamtheautomator.com
148 Upvotes

r/PowerShell • • Apr 18 '23

Fake Powershell code I wrote for my friends baby! I put it on a onesie

147 Upvotes
# Please Run CreateNewBorn.ps1 as Administrator

$Parents = @(Get-Parent | Where-Object {$_.Name -eq "Austin, Eliz"})

# Initialize Baby
$Baby = New-Person -TypeName Boy -Source $Parents.DNA
$Baby | Add-Attribute -Name "Cuteness" -Value "MAX"
$Baby.Love = "Full"

# Start Life
Start-Process -FilePath "Life.exe" -LoadUserProfile $Baby
Write-Output "Congratulations!"

r/PowerShell • • Dec 23 '20

Learn how to use secrets and password safely in PowerShell

147 Upvotes

Hello PowerShell peeps!

I write an article showing how to use the SecretsManagament module from Micosoft.

Learn how to manage your passwords and secrets from your PowerShell cmd prompt. I'll show you how to install, config and use the Microsoft SecretsManagement module in your daily workflow.

Feedback is always welcome. Happy holidays!

https://4sysops.com/archives/secretsmanagement-module-for-powershell-save-passwords-in-powershell/


r/PowerShell • • Jun 09 '21

What is PowerShell splatting and how does it work?

146 Upvotes

Hi all,

I recently posted an in-depth overview of the many uses of PowerShell splatting. Hopefully there is something useful in it for everyone. So, check it out at the link below and let me know what you think in the comments!

https://ryanjan.uk/powershell-splatting/

Cheers!


r/PowerShell • • Aug 05 '20

Microsoft Windows Terminal Setup using Chocolatey and Oh-My-Posh

Thumbnail
youtube.com
146 Upvotes

r/PowerShell • • Jun 12 '20

How to scan ip addresses range and get important details with Powershell GUI - Part 4 | Askme4Tech

Thumbnail
askme4tech.com
146 Upvotes

r/PowerShell • • Nov 23 '19

Script Sharing Sharing IT-ToolBox module

146 Upvotes

desert zealous homeless butter elderly connect voiceless compare touch sand

This post was mass deleted and anonymized with Redact


r/PowerShell • • Apr 08 '24

How did you learned PowerShell?

145 Upvotes

I’m getting into the shell and language. People in this sub helped me get finally committed to learning the language (here) and now I want to ask you what was your learning process, what resources did you used, and why you started with PS.


r/PowerShell • • Jan 15 '21

Aliases suck

145 Upvotes

Posted this in a reply to a separate thread but posting here to maybe get more folks onboard.

I truly wish folks would stop using aliases when helping people with code. Many (most?) of the questions here (and other forums) are from posters that are new to Powershell. Aliases just add another layer of confusion. As for me, I don't use them because 99% of what I do with PoSh is with scripts and using aliases in scripts makes them much harder to read. So yeah, I have to look them up too.

It's awesome that more experienced coders are willing to share their skill, it just seems to me it'd be awesomer if they would go that tiny extra mile to write out ForEach-Object instead of %, or Where-Object instead of ?, etc.

</whinge>


r/PowerShell • • Oct 06 '19

Powershell is actually costing me money...

144 Upvotes

I love powershell. At my primary job, I use it daily to save me and my team time. However, I also do alot of side jobs for a little hometown PC repair shop.

I took on a project hourly, so I knew what I was getting into. This job was mainly installing an AV Server, removing stand-alone AV from workstations, and then installing the agent from the new server. Easy-peasy... had I done it manually, each station 1 at a time, it probably would have taken few hours at least. But I scripted almost the whole thing, without realizing that I was screwing myself out of those extra hours.

TL;DR. Took on a job hourly. Used powershell to do it quickly and efficiently, Cost myself several hours pay.


r/PowerShell • • May 07 '18

PowerShell Universal Dashboard v1.6.0 Release!

Thumbnail
poshtools.com
144 Upvotes

r/PowerShell • • Jan 05 '17

PowerShell for beginners video training course as taught by its inventor, Jeffery Snover.

Thumbnail
mva.microsoft.com
144 Upvotes

r/PowerShell • • Mar 15 '16

¯\_(ツ)_/¯

144 Upvotes
function Get-AsciiShrug {
    $OutputEncoding = [System.Text.Encoding]::unicode
    write-output "¯_($(0x30C4|%{[char]$_}))_/¯" | clip
}

r/PowerShell • • Jan 03 '22

Script Sharing Welcome to 2022, your emails are now stuck in Exchange On-premises Transport Queues

143 Upvotes

Happy new year fellow redditors.

A new year means new surprises from your favorite software editor, Microsoft, right ?

If any of you are running on premise exchange mail system, you may encounter some issues within your emails, starting on the 1st.

Seeing every mail marked as DEFERRED when coming from a well deserved 2 days break where you cannot even rest a bit due to the festivities arround ?

That's how I like my first monday of the year, no coffee time this morning and already a queue full of critical level tickets.

Anyway, a patch script has been shared in order to correct this issue and get everything running on.

https://aka.ms/ResetScanEngineVersion or Link to the post.

Don't forget to set your execution policy to remotely signed before running the script or you'll run into some trouble:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Edit : If you want to keep track of the mails being delivered once you run the script, you can look at your message queue.

1..10 | % { get-queue | where identity -like "*submission*"; sleep -Seconds 5}

Best of luck y'all and I wish you the best for 2022


r/PowerShell • • Dec 06 '19

Windows PowerShell Introduction

Thumbnail
youtube.com
143 Upvotes

r/PowerShell • • Jul 08 '19

New module: kbupdate - get detailed info about KBs & download

143 Upvotes

My previous post got a lot of traction so I turned the script into a module. kbupdate is now available in the PowerShell Gallery and on GitHub. It's code-signed, xplat and now uses -UseBasicParsing (thanks /u/jantari!) It also has a new command Get-KbUpdate

Enjoy! Please file any issues or PRs here: https://github.com/potatoqualitee/kbupdate

If anyone has regex skills, that'd be welcomed. Otherwise, the module does use some old school split parsing. It'd be nice if Microsoft just fixed their RSS feed though.


r/PowerShell • • Oct 03 '18

Use PowerShell to Install the Remote Server Administration Tools (RSAT) on Windows 10 version 1809

Thumbnail
mikefrobbins.com
143 Upvotes

r/PowerShell • • Nov 28 '21

Bash vs PowerShell Cheat Sheet

Thumbnail blog.ironmansoftware.com
142 Upvotes

r/PowerShell • • Apr 28 '21

Script Sharing I created a PowerShell script for our HR department to use. I'm proud of it and just wanted to share it with everyone.

142 Upvotes

Maybe I'm doing this to inflate my ego, but oh well.

EDIT 1: Here is the github link that some of you requested. I'm new to GitHub so if something is wrong, let me know and I will change it! :)

TL;DR - I wrote a script for our HR department so my group didn't have to do their portion of their job. However our system is picky with passwords so I ended up not using it. But it was fun.

I'm 4 months new to my current company as a SysAdmin and recently there was a discussion that HR doesn't have the proper permissions to add new employee information into our system (which I thought was somewhat strange, but oh well). They usually pop and email over to me and my two coworkers to add the employee into our system. I had some extra time so I thought, "I'm going to see if I can script this".

Basically the script populates a form that asks for the employee ID, first name, last name, labor class, time type and shop. After that is all entered, it populates a separate form where the HR user can add the necessary roles for the new employee (timecard, employee type, etc.)

All the data gets added to our SQL database which houses all of the employee information as well as some other things. Once that has been added, if the user were to look in the actual system for the employee they would see all of their information properly set up. Was pretty slick, I thought.

Here is the code:

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing


## BUILDING THE FORM
##############################################################################################################################



## Position Variables
$okXPosition = 110
$okYPosition = 780

#

$cancelXPosition = 260
$cancelYPosition = 780

#

$formWidth = 500
$formHeight = 900

#

$loginLabelXPosition = 47
$loginLabelYPosition = 20

$loginFieldXPosition = 50
$loginFieldYPosition = 55

#

$empFirstLabelXPosition = 47
$empFirstLabelYPosition = 95

$empFirstXPosition = 50
$empFirstYPosition = 130

#

$empLastLabelXPosition = 47
$empLastLabelYPosition = 170

$empLastXPosition = 50
$empLastYPosition = 210

#

$laborClassLabelXPosition = 47
$laborClassLabelYPosition = 250

$laborClassFieldXPosition = 50
$laborClassFieldYPosition = 290

#

$empTypeLabelXPosition = 47
$empTypeLabelYPosition = 330

$empTypeMenuXPosition = 50
$empTypeMenuYPosition = 370

#

$roleLabelXPosition = 47
$roleLabelYPosition = 510

$roleMenuXPosition = 50
$roleMenuYPosition = 600

#

$timeTypeLabelXPosition = 47
$timeTypeLabelYPosition = 330

$timeTypeMenuXPosition = 50
$timeTypeMenuYPosition = 370

#

$shopLabelXPosition = 47
$shopLabelYPosition = 460

$shopMenuXPosition = 50
$shopMenuYPosition = 500





## Form itself
$objForm = New-Object System.Windows.Forms.Form 
$objForm.Text = "AiM Employee Form"
$objForm.Size = New-Object System.Drawing.Size($formWidth,$formHeight) 
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True
$objForm.Add_KeyDown({
    if ($_.KeyCode -eq "Enter" -or $_.KeyCode -eq "Escape"){
        $objForm.Close()
    }
})

<#
## OK Button
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(110,550)
$OKButton.Size = New-Object System.Drawing.Size(110,60)
$OKButton.Text = "OK"
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
#$OKButton.Add_Click({$objForm.Close()})
$objForm.AcceptButton = $OKButton
$objForm.Controls.Add($OKButton)
#>

## OK Button
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point($okXPosition,$okYPosition)
$OKButton.Size = New-Object System.Drawing.Size(110,60)
$OKButton.Text = 'OK'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$objForm.AcceptButton = $OKButton
$objForm.Controls.Add($OKButton)



###



## Cancel Button
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point($cancelXPosition,$cancelYPosition)
$CancelButton.Size = New-Object System.Drawing.Size(110,60)
$CancelButton.Text = "Cancel"
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
#$CancelButton.Add_Click({$objForm.Close()})
$objForm.CancelButton = $CancelButton
$objForm.Controls.Add($CancelButton)


###



## Employee ID/Login label
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size($loginLabelXPosition,$loginLabelYPosition) 
$objLabel.Size = New-Object System.Drawing.Size(325,30) 
$objLabel.Font = New-Object System.Drawing.Font("Lucinda",14,[System.Drawing.FontStyle]::Regular)
$objLabel.Text = "Employee ID"
$objForm.Controls.Add($objLabel) 






## Login field
$objTextBox = New-Object System.Windows.Forms.TextBox 
$objTextBox.Location = New-Object System.Drawing.Size($loginFieldXPosition,$loginFieldYPosition) 
$objTextBox.Size = New-Object System.Drawing.Size(400,20) 
#$objTextBox.Multiline = $true
$objTextBox.Font = New-Object System.Drawing.Font("Lucinda",16,[System.Drawing.FontStyle]::Regular)
#$objTextBox.Text = "(Employee ID)"
$objForm.Controls.Add($objTextBox) 

###


## Employee first name label
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size($empFirstLabelXPosition,$empFirstLabelYPosition) 
$objLabel.Size = New-Object System.Drawing.Size(325,30) 
$objLabel.Font = New-Object System.Drawing.Font("Lucinda",14,[System.Drawing.FontStyle]::Regular)
$objLabel.Text = "Employee First Name"
$objForm.Controls.Add($objLabel)






## Employee first Name field
$objTextBox2 = New-Object System.Windows.Forms.TextBox 
$objTextBox2.Location = New-Object System.Drawing.Size($empFirstXPosition,$empFirstYPosition) 
$objTextBox2.Size = New-Object System.Drawing.Size(400,20)
$objTextBox2.Font = New-Object System.Drawing.Font("Lucinda",16,[System.Drawing.FontStyle]::Regular) 
#$objTextBox2.Text = "(Employee Name)"
$objForm.Controls.Add($objTextBox2) 


###


## Employee last name label
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size($empLastLabelXPosition,$empLastLabelYPosition) 
$objLabel.Size = New-Object System.Drawing.Size(325,30) 
$objLabel.Font = New-Object System.Drawing.Font("Lucinda",14,[System.Drawing.FontStyle]::Regular)
$objLabel.Text = "Employee Last Name"
$objForm.Controls.Add($objLabel)




## Employee last Name field
$objTextBox3 = New-Object System.Windows.Forms.TextBox 
$objTextBox3.Location = New-Object System.Drawing.Size($empLastXPosition,$empLastYPosition) 
$objTextBox3.Size = New-Object System.Drawing.Size(400,20)
$objTextBox3.Font = New-Object System.Drawing.Font("Lucinda",16,[System.Drawing.FontStyle]::Regular) 
#$objTextBox2.Text = "(Employee Name)"
$objForm.Controls.Add($objTextBox3) 


###


## Labor Class Label
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size($laborClassLabelXPosition,$laborClassLabelYPosition) 
$objLabel.Size = New-Object System.Drawing.Size(325,30) 
$objLabel.Font = New-Object System.Drawing.Font("Lucinda",14,[System.Drawing.FontStyle]::Regular)
$objLabel.Text = "Labor Class"
$objForm.Controls.Add($objLabel)


## Labor Class Field
$objTextBox4 = New-Object System.Windows.Forms.TextBox 
$objTextBox4.Location = New-Object System.Drawing.Size($laborClassFieldXPosition,$laborClassFieldYPosition) 
$objTextBox4.Size = New-Object System.Drawing.Size(400,20)
$objTextBox4.Font = New-Object System.Drawing.Font("Lucinda",16,[System.Drawing.FontStyle]::Regular) 
#$objTextBox2.Text = "(Employee Name)"
$objForm.Controls.Add($objTextBox4) 


###


## Time type label 
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size($timeTypeLabelXPosition,$timeTypeLabelYPosition)
$objLabel.Size = New-Object System.Drawing.Size(325,30)
$objLabel.Font = New-Object System.Drawing.Font("Lucinda",14,[System.Drawing.FontStyle]::Regular)
$objLabel.Text = "Select Time Type"
$objForm.Controls.Add($objLabel)




## Time type menu 
$listbox2 = New-Object System.Windows.Forms.ListBox
$listbox2.Location = New-Object System.Drawing.Point($timeTypeMenuXPosition,$timeTypeMenuYPosition)
$listbox2.Size = New-Object System.Drawing.Size(400,20)
$listbox2.Font = New-Object System.Drawing.Font("Lucinda",12,[System.Drawing.FontStyle]::Regular)
$listbox2.Height = 90

[void] $listBox2.Items.Add('REGULAR')
[void] $listBox2.Items.Add('OVERTIME')
[void] $listBox2.Items.Add('COMP EARNED')
[void] $listBox2.Items.Add('OVERDBL')
[void] $listBox2.Items.Add('SAFETY OVT')
[void] $listBox2.Items.Add('SAFETY COMP')
[void] $listBox2.Items.Add('COMPDBL')


$objForm.Controls.Add($listBox2)




## Help/label prompt for SHOP
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size($shopLabelXPosition,$shopLabelYPosition) 
$objLabel.Size = New-Object System.Drawing.Size(325,40) 
$objLabel.Font = New-Object System.Drawing.Font("Lucinda",14,[System.Drawing.FontStyle]::Regular)
$objLabel.Text = "Select Shop"
$objForm.Controls.Add($objLabel)






## Drop down menu for SHOP
$listBox1 = New-Object System.Windows.Forms.ListBox
$listBox1.Location = New-Object System.Drawing.Point($shopMenuXPosition,$shopMenuYPosition)
$listBox1.Size = New-Object System.Drawing.Size(400,20)
$listBox1.Font = New-Object System.Drawing.Font("Lucinda",12,[System.Drawing.FontStyle]::Regular)
$listBox1.Height = 270

#$listBox.SelectionMode = 'MultiExtended'

[void] $listBox1.Items.Add('ADMIN')
[void] $listBox1.Items.Add('BUSSERV')
[void] $listBox1.Items.Add('CARPENTERS')
[void] $listBox1.Items.Add('CEP')
[void] $listBox1.Items.Add('COMMISSION')
[void] $listBox1.Items.Add('CUSTSERV')
[void] $listBox1.Items.Add('D&C')
[void] $listBox1.Items.Add('DIRECTOR')
[void] $listBox1.Items.Add('DISTRIBUTE')
[void] $listBox1.Items.Add('ELECTRICAL')
[void] $listBox1.Items.Add('ENERGYMGMT')
[void] $listBox1.Items.Add('EQUIPOPER')
[void] $listBox1.Items.Add('EVENTUTILS')
[void] $listBox1.Items.Add('FINISHES')
[void] $listBox1.Items.Add('FM')
[void] $listBox1.Items.Add('HIGHVOLT')
[void] $listBox1.Items.Add('HVAC')
[void] $listBox1.Items.Add('LABGAS')
[void] $listBox1.Items.Add('LIFTMAINT')
[void] $listBox1.Items.Add('LOAM')
[void] $listBox1.Items.Add('LOCKSMITH')
[void] $listBox1.Items.Add('MAINTADMIN')
[void] $listBox1.Items.Add('MIS')
[void] $listBox1.Items.Add('MOVING')
[void] $listBox1.Items.Add('PARTEAM')
[void] $listBox1.Items.Add('PLANNING')
[void] $listBox1.Items.Add('PLUMBERS')
[void] $listBox1.Items.Add('PROJ&ENGR')
[void] $listBox1.Items.Add('PROJECTS')
[void] $listBox1.Items.Add('PURCHASING')
[void] $listBox1.Items.Add('RCDEMGR')
[void] $listBox1.Items.Add('RECEIVING')
[void] $listBox1.Items.Add('RECPOSTAGE')
[void] $listBox1.Items.Add('RECYCLING')
[void] $listBox1.Items.Add('SAFETY')
[void] $listBox1.Items.Add('SECURITY')
[void] $listBox1.Items.Add('SNOW REMOVAL')
[void] $listBox1.Items.Add('STORAGE')
[void] $listBox1.Items.Add('SUPPTADMIN')
[void] $listBox1.Items.Add('SURPLUS')
[void] $listBox1.Items.Add('UTILADMIN')
[void] $listBox1.Items.Add('UTILITIES')
[void] $listBox1.Items.Add('WAREHOUSE')
[void] $listBox1.Items.Add('WASTEMGMT')
[void] $listBox1.Items.Add('WATERQLTY')


$objForm.Controls.Add($listBox1)

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
#[void]$objForm.ShowDialog()


$result = $objForm.ShowDialog()

## Add results to variables and display data ONLY if 'OK' is pressed
##############################################################################################################################

if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
    $Login = $objTextBox.Text ## Employee ID
    $FirstName = $objTextBox2.Text ## First Name
    $LastName = $objTextBox3.Text ## Last Name
    $LaborClass = $objTextBox4.Text ## Labor Class
    $Description = $objTextBox2.Text + " " + $objTextBox3.Text ## Description = first name and last name
    $EmployeeID = $objTextBox.Text ## Employee ID
    $Password = "P@$$w0rd" ## Password
    $EmployeeType = "S"
    $TimeType = $listbox2.SelectedItem
    $Shop = $listBox1.SelectedItem ## Employee Shop
    #$Shop = $objTextBox4.Text
    #$Role = @($listBox.SelectedItems)
    
    ## Confirm variables. Used for testing
    <#
    $Login
    $FirstName
    $LastName
    $Description
    $Password
    $LaborClass
    $EmployeeID
    $EmployeeType
    $TimeType
    $Shop
    #$Shop
    #$Role
    #$Role.GetType()#>

    ## Sql Statement to insert employee information
    $EmployeeInfo = "INSERT INTO table1 (login, description, password, employee_id, shop, default_org, active)
    VALUES ('$Login', '$Description', '$Password', '$EmployeeID', '$Shop', 'N', 'Y')
    "

    ## Pass query to SQL Server & return results
    $Pass = Invoke-Sqlcmd -Query $EmployeeInfo -ServerInstance "SERVER IP" -Username "USERNAME" -Password "PASSWORD"
    #$Pass




    ## Sql statement to insert values into HR table
    $HRTable = "INSERT INTO table2 (shop_person, fname, lname, time_type, labor_class, active, emp_type)
    VALUES ('$Login', '$FirstName', '$LastName', '$TimeType', '$LaborClass', 'Y', '$EmployeeType')
    "


    ## Pass query to SQL
    $EmployeeProfileUpdate = Invoke-Sqlcmd -Query $HRTable -ServerInstance "SERVER IP" -Username "USERNAME" -Password "PASSWORD"


} ## End 'IF' Statement

## ROLES Prompt now that the user has been added
##############################################################################################################################

if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
    
    ## Perform this task until the "finish" button is pressed
    do
    {

        ## Position Variables
        $doneXPosition = 360
        $doneYPosition = 400

        $cancelXPosition = 360
        $cancelYPosition = 400

        $addXPosition = 50
        $addYPosition = 400

        $formWidth = 500
        $formHeight = 530

        $LabelXPosition = 100
        $LabelYPosition = 20

        $roleMenuXPosition = 50
        $roleMenuYPosition = 120



        ## Form itself
        $objForm = New-Object System.Windows.Forms.Form 
        $objForm.Text = "AiM Employee Roles"
        $objForm.Size = New-Object System.Drawing.Size($formWidth,$formHeight) 
        $objForm.StartPosition = "CenterScreen"

        $objForm.KeyPreview = $True
        $objForm.Add_KeyDown({
            if ($_.KeyCode -eq "Enter" -or $_.KeyCode -eq "Escape"){
                $objForm.Close()
            }
        })


        ## Done Button
        $DoneButton = New-Object System.Windows.Forms.Button
        $DoneButton.Location = New-Object System.Drawing.Point($doneXPosition,$doneYPosition)
        $DoneButton.Size = New-Object System.Drawing.Size(90,35)
        $DoneButton.Text = 'Finish'
        $DoneButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
        $objForm.AcceptButton = $DoneButton
        $objForm.Controls.Add($DoneButton)

        <#

        
        ## Cancel Button
        $CancelButton = New-Object System.Windows.Forms.Button
        $CancelButton.Location = New-Object System.Drawing.Size($cancelXPosition,$cancelYPosition)
        $CancelButton.Size = New-Object System.Drawing.Size(90,35)
        $CancelButton.Text = "Cancel"
        $CancelButton.Add_Click({$objForm.Close()})
        $objForm.Controls.Add($CancelButton)
        
        ###>


        ## Add Button
        $AddButton = New-Object System.Windows.Forms.Button
        $AddButton.Location = New-Object System.Drawing.Point($addXPosition,$addYPosition)
        $AddButton.Size = New-Object System.Drawing.Size(90,35)
        $AddButton.Text = 'Add'
        $AddButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
        $objForm.AcceptButton = $AddButton
        $objForm.Controls.Add($AddButton)




        ## Label/help 
        $objLabel = New-Object System.Windows.Forms.Label
        $objLabel.Location = New-Object System.Drawing.Size($LabelXPosition,$LabelYPosition) 
        $objLabel.Size = New-Object System.Drawing.Size(325,80) 
        $objLabel.Font = New-Object System.Drawing.Font("Lucinda",14,[System.Drawing.FontStyle]::Regular)
        $objLabel.Text = "Select one Role at a time then press 'Add'. Press 'Finish' when done."
        $objForm.Controls.Add($objLabel) 




        ## Drop down menu for ROLES
        $listBox = New-Object System.Windows.Forms.ListBox
        $listBox.Location = New-Object System.Drawing.Point($roleMenuXPosition,$roleMenuYPosition)
        $listBox.Size = New-Object System.Drawing.Size(400,20)
        $listBox.Font = New-Object System.Drawing.Font("Lucinda",12,[System.Drawing.FontStyle]::Regular)
        $listBox.Height = 260

        #$listBox.SelectionMode = 'MultiExtended'

        [void] $listBox.Items.Add('SHOP_FOREMAN')
        [void] $listBox.Items.Add('SHOP_PERSON')
        [void] $listBox.Items.Add('TIME_CARD')
        [void] $listBox.Items.Add('EXEMPT')
        [void] $listBox.Items.Add('HOURLY')
        [void] $listBox.Items.Add('NON-EXEMPT')



        $objForm.Controls.Add($listBox)


        $objForm.Topmost = $True

        $objForm.Add_Shown({$objForm.Activate()})
        #[void]$objForm.ShowDialog()


        $result2 = $objForm.ShowDialog()



        ## If the user presses "add", add roles to specified user
        if ($result2 -eq [System.Windows.Forms.DialogResult]::OK)
        {
            $Role = @($listBox.SelectedItems)
            #$Role

            ## Sql Statement to add Roles to specified user
            $EmployeeRoles = "INSERT INTO table3 (role_id, login)
            VALUES ('$Role', '$Login')
            SELECT t3.role_id, t3.login
            FROM
            table3 t3
            INNER JOIN
            table1 t1 ON (t3.login = t1.login)
            WHERE
            t1.login = '$Login'
            "
        
            $ExecuteRoleQuery = Invoke-Sqlcmd -Query $EmployeeRoles -ServerInstance "SERVER IP" -Username "USERNAME" -Password "PASSWORD"

        }



    } while ($result2 -ne [System.Windows.Forms.DialogResult]::Cancel)

}
#>

I started using PS2EXE to create this into an executable as well as an 'installation script' for the HR department (this script obviously requires SqlServer Module and some other things) and was feeling pretty good. Alas, the password portion of the script was a bust. I found out that our system only stores passwords into the database that were set WITHIN the system itself, not by updating the database on the backend. Everything else still works, however this would mean that my group would still have to log in and change the password, defeating the purpose of the script.

Oh well though. It was a fun project and I get to keep it for reference for a possible future project and who knows what else.


r/PowerShell • • Feb 24 '21

How to create a simple Powershell GUI Menu to launch your scripts

Thumbnail
smarthomepursuits.com
142 Upvotes

r/PowerShell • • Feb 04 '21

Sometimes boredom leads to innovation... sometimes, it's Pure-Evil

142 Upvotes
function Pure-Evil{
DO {
IF ((Get-clipboard) -gt $null){Set-Clipboard $null}
} while ($True)
}

Bonus points if used during a remote support session w/ a vendor


r/PowerShell • • Oct 06 '20

Information Free 1-hour PowerShell training, on Windows 10 Notifications, for one week!

142 Upvotes

r/PowerShell • • Apr 09 '18

Free PowerShell PDF Book

Thumbnail
book.goalkicker.com
142 Upvotes