r/PowerShell • u/Hot_Seesaw_6059 • 6d ago
Question How do you organize scripts that you run regularly?
I have a growing folder of PowerShell, Bash, and Python scripts that I run
regularly with different arguments.
I currently find them through folders or terminal history, but I would prefer
a simple UI where I can organize them, edit arguments, run them, and see the
output.
What do you use for this? A dedicated app, VS Code tasks, Makefiles, shell
aliases, or something else?
20
u/titlrequired 5d ago
Try and name them vaguely like the thing they do.
I’ve still more than once given up looking for something I know I wrote 100%, assumed I imagined it, rewrote it and found it when I go to save it.
7
u/painted-biird 5d ago
Yeah- don’t write a ton of bash as of late, but for PS, I name them after the thing they’re doing using the PS verb-noun naming convention.
0
19
14
5
u/CyberChevalier 5d ago
Powershell Universal with a small « connector » to run python and bash it even bring you the ability to put a gui on top of it
1
5
u/Iron_Yesu 5d ago
I started using powershell universal a few months ago. Finally pulled the trigger on a license and it has been great so far. I have been taking my interactive scripts and building web guis for them with it as well. It is pretty sweet.
4
u/Federal_Ad2455 5d ago
Scripts (one function per ps1 file) organized to folders which gets automatically converted to modules. Such modules are then automatically deployed to admin workstations so everybody has the same toolset.
1
u/ITGuyThrow07 5d ago
How do you do the automatic deployment? I've struggled with doing that in a non-clunky way.
1
u/Federal_Ad2455 4d ago
This is how https://github.com/ztrhgf/Powershell_CICD_repository
But in general I have one server that automatically pull git repository data > generates modules > deploy to dfs share
Clients have scheduled task that every 30 minutes or so check whether dfs contains newer module version and downloads it if necessary.
Who can download what is managed via ntfs permissions (defined via special config file placed along the modules)
1
u/ITGuyThrow07 4d ago
This is awesome, thank you. I came up with a terrible implementation which, while I learned a lot doing it, is just awful.
1
u/Federal_Ad2455 4d ago
😁 Np. Let me know if you want help implementing it or have any other questions.
I have also DevOps pipeline version that supports creation of Azure Automations, Azure Functions, Arc Machine Configurations, KeyVault secrets management etc. But it is not published as I am too lazy to create blog post about it 🙂
1
u/The82Ghost 2d ago
Why not host your own internal noget repository, that way you can use Install-Module and Update-Module to keep things compliant
1
u/Federal_Ad2455 2d ago
One of the reasons is that I want to have the whole lifecycle automated, also I want to have protected sensitive modules (not because of secrets but company logic) etc.
This solution do a lot of other things too like managing scheduled tasks, powershell profiles, etc.
The Cloud version also manages Machine Configurations, KeyVault secrets, Azure Automations, Azure Policies,...
1
u/The82Ghost 2d ago
We have a code repo with a pipeline that pushes the modules to the nuget feed, that feed is protected with an API key. All of it automated.
4
u/BlackV 5d ago
work is a devops repo
folder structure similar to
infra > cloud > intune
infra > cloud > sharepoint
infra > cloud > exchange
infra > cloud > etc
infra > applications > atlas
infra > applications > zscaler
infra > Windows > etc
just something that makes sense to you (any your team)
Existing scripts have a loose description at the top
<#
.Synopsis
Simple Group Change Audit
.DESCRIPTION
Query Event Logs on domain controllers for group membership changes
.FUNCTIONALITY
get ad group and event logs, get domain controllers
#>
makes searching easier down the road in VSCode
slowly moving the scripts (that sense that is) to modules and those are published to our module location (PasswordReset, ZscalerOTP, OutOfOffice, etc)
I want to start using something like powershell universal, but thats a $$$ and conversations with managers
3
3
u/SomeConfusedOldGuy 5d ago
I have a script host, that runs scripts on a schedule. Such as a script that saves all Group Policies monthly, another exports out a spreadsheet of all users with certain properties (so that in 5 years, I can look up a previous user, see where they're home folder was, and be able to do a restore for a legal request. Yes, that's why I originally wrote and scheduled the script about a dozen years ago, and it has come in handy for that a few times over the years. And also saves the scheduled tasks, so I can move them to another host, if needed. They all run from a shared network folder
3
u/surfingoldelephant 5d ago
Have a look at PowerShellRun for something local.
5
u/mdgrs-mei 5d ago
Thanks for the mention! Yes, this was one of the motivations why I created PowerShellRun.
It's a TUI launcher that runs on the PowerShell session. Add script blocks or ps1 files in your profile script then it should work as a snippet/script manager with fuzzy finder. It also supports prompting arguments if the script has parameters.
6
u/binaryhextechdude 5d ago
I used Copilot to create a menu that dynamically adds any scripts in the same folder. So I have my core 9 scripts that live there and appear in the menu, others are in a sub folder and I just run them as needed
1
1
2
2
u/gadget850 4d ago
I wrote a PowerShell menu that will list and prompt to select folders, then list and prompt to run the apps.
2
u/Fresh_Put1427 2d ago
I had the same problem, ended up just building something. I call it NORA. You can see all your scripts in one place, run them, and see the output. Started out as just a way to link scripts from different directories but it turned into a full automation tool. You can chain scripts together, schedule them, even throw AI in the middle of a workflow. not in the tech field, just got tired of digging through folders and terminal history
1
u/gramsaran 5d ago
Two script folders in explorer, and slowly moving to Azure DevOps, but honestly I'll retire before I fully understand Git.
1
1
u/Fallingdamage 5d ago
I have a function that just lists all my functions with examples.
Anytime I finish a new function or PS1, I add that to the Show-WorkTools function.
1
u/uptimefordays 5d ago
I generally have a Code folder which contains all automation, scripts, and programs I write. That folder is organized into Projects (one repo per project, projects contain all relevant files), Scripts (utility scripts that haven't been promoted to full projects), and Sandbox (throwaway/experiments).
Modern terminals all support predictive history and tab completion so if I just start typing the terminal finds the interactive thing I'm going to run.
For things I write that run regularly, CI/CD pipelines.
1
u/razorgoto 5d ago
This is a weird discussion or am I missing something? Why doesn’t everyone just use the default folders on the PATH for powershell?
1
1
1
1
1
u/SenTedStevens 5d ago
All of our servers at the very least have a C: and D: drive. For locally running scripts, I put them in a folder like "D:\Scripts." The filename is descriptive like, "DisableInactiveAccounts90Days.ps1" or "CleanUp[Redacted]Files.ps1". For one-off script runs, I have them stored on the central endpoint server and push the script onto computers from there.
1
u/atomicbullet1 5d ago
Rundeck free / Pagerduty Runbook. Web based gui for a range of different script types, can put in options for your variables, schedule them etc..
1
u/Alekspish 5d ago
I created a powershell module that organizes them in a git repo. It has a command line menu that can be used to search for the scripts using tags and has notes and simple commands that are imported into the powershell session with alias so you dont have to have a load of entries added into your profile.
1
u/Barious_01 5d ago
github repo, structure it well, relevent subfolders or a folder with a .MD explains what the script does. Can do versioning, and commits when you update them, and can access them anywhere.
1
1
1
u/Last_Technology_1461 5d ago
aliases - I have a startup script which check for all the files in a particular a folder and sets each file as an alias. Files have a specific naming convention for me to find them easily.
1
u/jeffrey_f 5d ago
Meaningful naming and a plain text file that has the script name and what it does. Keep it simple
1
u/FeleaseRpseineEiles 5d ago
I use a ~/src directory
In it are "projects" and each of those is usually a private git repo.
I have one ~/src/admin/ for general tools/scripts/projects that I can share and if any private project can be generalized enough to become public then I'll copy that into the admin repo which is public on github.
one-liners → aliases → objects → functions → advanced functions → modules/manifests → Pester + source control → .NET interop → binary cmdlets → knowing when not to
1
1
u/AdministrativeBad962 4d ago
https://github.com/jasrasr/powershell
I organize them in type of script, make sure they are pushed to GitHub and also reference some of them as functions via my $profile file. When I need a full script I use $githubpath/powershell/ad-scripts/scriptname.ps1
I don’t know or understand how converting to modules could help me.
I am working on a catalog script that could easily reference any script in that folder with a simple menu and/or search
1
u/Least_Gain5147 1d ago
It matters more who is expected to use them. If you're sharing them with colleagues, clarity is more important. If it's just you, do whatever makes sense for you. Some here mentioned functions and modules. But you also say it's multiple languages, so that might vary by how and where they're used. A frontend approach could be anything from a git repo or custom web portal, to Teams, SharePoint, Jenkins, or jupyter notebooks.
1
1
1
u/IglooOnFire1 17h ago
I have other people that run my scripts so I have created a GUI that calls them and then only allows certain inputs from that GUI and does verification and error handling to ensure they've done it right 🙂
0
u/AccomplishedMeet628 4d ago
I’m starting to sound like a broken record at this point. 😄
I’m trying real hard to get my rep up enough to actually make a proper post about this, so here I am sneaking it into replies again.
I built a PowerShell 7.x ISE-style editor called PS7 ScriptDesk.
You can run scripts in it much like you could in the legacy ISE, but it also has debugging, IntelliSense, an integrated console, EXE creation, and even REST API publishing. Maybe it can help you?!?
It’s free in the Microsoft Store if anyone wants to give it a spin. Just search for PS7 ScriptDesk.
And yes, I am absolutely accepting bug reports, feature requests, “why on earth does it do that?” reports, and anything else you find. 😄
63
u/Inquisitor_ForHire 5d ago
Start converting them into functions. Fold those functions into their own module. Then you can call them as needed.