r/PowerShell • u/weebsnore • Oct 09 '19
PSScriptMenuGui - Use a CSV file to make a graphical menu of PowerShell scripts
1
u/graysky311 Oct 09 '19 edited Oct 09 '19
JSON would make more sense because it's got a one-to-many structure and even nested objects. Can't do that with CSV without loads of duplication.
Edit: also with JSON you can take advantage of built-in serialization and deserialization of objects and strings which is not something that comes for free with Export-CSV or Import-CSV
2
u/weebsnore Oct 09 '19
I started with CSV because of my target audience and the familiarity/Excel factor, but I wouldn't rule out supporting other formats in the future.
That said - if the project starts needing a more advanced format to be usable, maybe something has gone wrong. It's meant to be simple!
1
u/graysky311 Oct 15 '19
I wanted to mention this. It’s free and simple to generate a menu of commonly used scripts without a lot of coding. Although it mentions SQL it doesn’t have to be used for that. https://www.red-gate.com/simple-talk/sql/sql-tools/sql-scripts-manager-with-powershell/
1
u/boomertsfx Oct 11 '19
YAML is much more human readable
1
u/graysky311 Oct 11 '19
I’ll take your word on that. Have never touched YAML. I’m guessing it’s based on XML?
1
u/boomertsfx Oct 11 '19
Thankfully, no.... It's its own thing and can do everything XML and JSON can do, and it's easier for humans to parse!
1
u/graysky311 Oct 15 '19
I’m not seeing any native PowerShell functionality for working with YAML. Seems like that would not be an obvious first choice for anyone scripting in PowerShell. The YAML project page doesn’t acknowledge PowerShell as a supported language. I would be hesitant to bolt on a third party module just to adopt yet another markup language.
3
3
u/edelwater Oct 09 '19 edited Oct 09 '19
I do the same calling windows forms assembly for stuff, I have a bunch of functions (which could indeed be read by a source file but i find it handier to just have 1 ps1 file. E.g:
function Tskschd { Start-Process -FilePath "$($env:windir)\system32\taskschd.msc"}
function Regedit { Start-Process -FilePath "$($env:windir)\system32\regedt32.exe"}
function SoundVolume { Start-Process -FilePath "$($env:windir)\system32\sndvol.exe"}
function Programs { Start-Process -FilePath "$($env:windir)\system32\appwiz.cpl"}
function Azman { Start-Process -FilePath "$($env:windir)\system32\azman.msc"}
function Cert { Start-Process -FilePath "$($env:windir)\system32\certlm.msc"}
function Services { Start-Process -FilePath "$($env:windir)\system32\services.msc"}
function Firewall { Start-Process -FilePath "$($env:windir)\system32\wf.msc"}
function Tpm { Start-Process -FilePath "$($env:windir)\system32\tpm.msc"}
function Compmgmt { Start-Process -FilePath "$($env:windir)\system32\compmgmt.msc"}
function Comexp { Start-Process -FilePath "$($env:windir)\system32\comexp.msc"}
function Ssms {Start-Process -FilePath "C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe"}
function HackerNews {Start-Process -FilePath "https://news.ycombinator.com/"}I then have: buttons like this:
NewButton -text "TaskScheduler" -execute ${function:Tskschd} -panel $t1
function NewButton {
Param ([string] $text,[System.EventHandler] $execute, [System.Windows.Forms.TabPage]$panel)
$button = New-Object System.Windows.Forms.Button
$button.Size = New-Object System.Drawing.Size(200,200)
$button.Text = $text
$button.Add_Click($execute)
$panel.Controls.Add($button)
}The buttons are placed on a windows forms tabpage inside a tabcontrol with the tabcontrol location on the left to have vertical list of "bookmarks", "apps", "utilities" etc.. I have been thinking on reading the FireFox Bookmarks Sqlite places table for my bookmarks hierarchically and then adding this automatically to the ps1 script in the bookmarks part with a tree control. To have always a synced bookmarks set in 1 ps file and so I dont have to keep the firefox side tab open for all my bookmark folders.
3
u/Lee_Dailey [grin] Oct 09 '19
howdy edelwater,
it looks like you used the New.Reddit.com
Inline Codebutton. it's4th5th from the lefthidden in the..."more" menu & looks like</>.on Old.Reddit.com, the above does NOT line wrap, nor does it side-scroll.
for long-ish single lines OR for multiline code, please, use the
Code Blockbutton. it's the11th12th one from the left, & is just to the left ofhidden in the..."more" menu.that will give you fully functional code formatting, from what i can tell so far. [grin]
take care,
lee
3
Oct 09 '19
Very cool way to allow less technical coworkers to run the scripts without the "scary terminal". Definitely going to play around with this, thanks for sharing!
2
2
u/Lazzexus Oct 14 '19
I love this. Been using and running powershellscripts from the PS terminal for quite a while, but my colleagues refuse to use it because they're not as comfortable with PS as I am. Created a .bat-file which runs that script elevated since our logon-accounts don't have admin privileges.
powershell -noprofile -command "&{ start-process powershell -ArgumentList '-noprofile -file C:\pstools\Scripts\PSScriptMenuGui.ps1' -verb RunAs}"Change the block after -file to the directory where the file is stored, it will prompt for credentials and run as that credential.
1
u/geethreeforce Oct 21 '19
Nice. I was working on simple character-based menus for our servicedesk to allow them to run my recently written unattended installation-scripts which in turn build, install and configure full servers according to their roles. RDS / FilePrint / RODC / Dev
I’ll give this a go. Looks more nice and could save me some time. I’ll blow the horn if I like it. Will post feedback on your PSGallery page.
-18
25
u/weebsnore Oct 09 '19 edited Oct 09 '19
Here's something I've been working on.
Launches fast and works with PowerShell 5.1 and 7-preview!
It's imagined as a good way of sharing scripts with frontline staff.
Useful to anyone?
More here: https://github.com/weebsnore/PowerShell-Script-Menu-Gui
Edit: If you like this, please consider following/retweeting on Twitter. I have pitifully few followers 😁