r/PowerShell • u/islanderfj • May 23 '26
Question Powershell - curating and organizing scripts
I'm fairly new to Powershell, have dabbled into it here and there throughout the years, but now that I am fully immerse in supporting SCCM, I find the need to document and store useful scripts. What do the gurus use? I want something cross platform and easy to pull up and search through a library of scripts possibly with tags. etc.
24
Upvotes
19
u/alconaft43 May 23 '26
guthub for repo, azure dev ops artifacts for publishing
16
u/StartAutomating May 23 '26
I write a lot of PowerShell, so I have a lot of thoughts and experience with this.
I'm still constantly evolving, but here are seven things I try to do at this point:
Anyone is welcome to their own naming conventions / design patterns. I'm hopeful these might help you on your journey. Good luck!
11
u/BlackV May 23 '26
Hopes and dreams, is how I organize it
4
u/durgan2q May 24 '26
For naming schemes you kinda have to feel it out on your own but I try and do <Environment>_<what it does>_<email/export>_<job>ps1. Email/export to tell if it emails or exports a file and job if it uses the job system. Also add a comment section at the top for version history and details on exactly what the script does and who wrote it.
So a script thst audits AD for machine information and emails a report would be AD_Machine_Info_email.ps1 or a script that deploys a reg key to some citrix servers Citrix_A_Servers_Security_Reg_Key_job.ps1. I know it can be long but its hard to keep up with 300+ scripts and what each one does but I still have to look at the script and the comments at the top for detailed info on what it does.
Im still evolving my processes after 15 years so dont sweat it if it takes some adjusting.
3
u/thehuntzman May 23 '26
Obsidian notes backed to onedrive for snippets (fast and easy search with native codeblock support + very portable since it's just a bunch of markdown documents on the back-end) and onedrive with a good folder structure for personal scripts / projects. The important non proprietary ones in onedrive also get synced to github.
For work it's basically the same but Onedrive for Business, Obsidian notes, and Github Enterprise.
2
u/justaguyonthebus May 23 '26
Generally store them all in a git repo. Then work them into modules so you can discover and run them from within powershell.
2
u/heyitsgilbert May 23 '26
The default guru answer should always be, "it depends." Regularly deployed functions that fit together, make a module. Random one-offs? Your note / snippet tool of choice.
Anything that can use a CI to test and validate your code is always going to be better. For snippets sometimes that doesn't really matter, especially when they're extremely short-lived and rarely to be used again. For example a one-liner that I used to handle some random edge case deletion - I don't care that a store that in a gist with aliases. For a set of functions to manage certificates and different things about certificates - that gets its own certificate module.
Once it meets the criteria of a module then it gets the full release treatment. Proper versioning, tests, pipeline input, etc. Everything in a repo. The reason: if you ever release something bad and you know you had a working version you can just pin to the working version.
2
u/BlkCrowe May 24 '26
Scripts. Copy of Scripts. Copy of Scripts (1). Copy of Copy of Scripts. Working Scripts. Backup of Working Scripts. Copy of Backup of Working Scripts.
2
u/turbokid May 23 '26
Github
1
u/PinchesTheCrab May 23 '26
Version control and a PS repository.
For version control just use whatever GIT flavor your company uses. It'll take some time to learn, but don't overthink it. https://xkcd.com/1597/
If you use VS Code (you should), you won't even need to know the git commands at first, though they'll come in handy down the road. CoPilot and other AIs are pretty good at translating some basic requests into GIT commands, and you'll absorb it eventually.
GIT will both help you organize things for yourself and share them with your team, albeit with some overhead for everyone to learn the GIT basics.
As for the PS repo, it's optional and I would drag my feet on implementing it if I weren't sharing scripts with other people right off the bat. A PS repo lets your team use the built-in search commands like Find-Script, Find-Module, Update-Module, or Find-PSResource (depends on your PSGet version).
Anyway, just try to balance building a mess you'll have to clean up later vs getting things done right now. Sometimes it's okay to incur some tech debt if it helps you get things done. Just don't let it get out of hand.
1
u/richie65 May 24 '26
For about the past 17 years - As my collection of scripts kept growing...
At first I would email them to my personal account...
Then I started saving them on to two separate external drives...
I had scripts and tasks that did this automaticaally
Then Google Drive came along, and OneDrive (personal) - and I started saving my scripts to those as well (automatically).
Then I added GitHub to the mix.
When my boss (who couldn't write a script without help, to save his life) decided that theres is no need for me to save stuff to Google Drive - and the no one in the company needed it - He blocked Google Drive, because o365 OneDive is what we use (never-mind that there is no reason to trust o365 OneDrive at all - Files disappear)
So - I use RCLONE, and scheduled tasks to back up my stuff to my personal cloud (Google Drive and OneDrive)...
Then other tasks on my home computer - that copy from Google Drive to those same external drives I have had for 17 years.
And I also have a script that parses the contents of those scripts for whatever text I'm looking for - So I can locate a specific script...
1
u/[deleted] May 24 '26
Git + GitHub/GitLab/Azure DevOps (la soluzione dei veri guru)
È lo standard del settore.
Perché è la scelta migliore:
• multipiattaforma (Windows, Linux, macOS) • versionamento automatico • puoi taggare, commentare, documentare • ricerca istantanea in tutta la codebase • puoi creare cartelle per moduli, funzioni, snippet, SCCM, automazioni, ecc. • perfetto per lavorare in team
Setup consigliato:
• una repo chiamata powershell-library • cartelle tipo:• /SCCM • /Intune • /Modules • /Functions • /Snippets • /Archived
1
u/node77 May 24 '26
Bit bucket with GitHub.
1
u/Nydus87 May 24 '26
UsefulScripts.psm1
length: several thousand lines and growing
1
u/The82Ghost May 24 '26
Use github or Azure DevOps, also makes it very easy to work on those scripts with multiple people.
1
u/markdmac May 25 '26
Bitbucket
0
u/[deleted] May 23 '26
[removed] — view removed comment