r/PowerShell • u/techstress • Feb 27 '22
r/PowerShell • u/sqllqs • Aug 24 '22
Question "You don't "learn" PowerShell, you use it, then one day you stop and realize you've learned it" - How true is this comment?
Saw it on this sub on a 5 year old post, I was looking around for tutorials, are they even relevant? Is Powershell in a month of lunches worth it? Or how about this video with the creator is it too old?
r/PowerShell • u/PMental • Nov 26 '20
Who else has spent hours writing a really complex script, only to realize there was a much simpler way?
So I spent a few hours digging through https://www.pinvoke.net/ and Microsofts Win32Api documentation and ended up with a 272 line function. Only to then realize the complex P/Invoke-stuff could be replaced by two simple CmdLets.
Ended up with a 47 line function...
A bit annoying, but learned a lot (been looking for excuses to use P/Invoke anyway), so not really a loss of course.
r/PowerShell • u/MartinGC94 • Sep 25 '24
News Do you want PowerShell 7 included with Windows? Let your voices be heard
The PowerShell team is asking for user input and scenarios about why we want PowerShell 7 in Windows: https://github.com/PowerShell/PowerShell/discussions/24340
If you have any good reasons, let them be known. Note that just like here on Reddit there's an upvote feature so you don't need to respond with "me too" or "I agree". You can just upvote a response if you don't have anything else to add.
r/PowerShell • u/bradsfoot90 • Mar 04 '22
Uncategorised I wrote the mother-of-all onboarding scripts and now everyone blames me for everything...
About a year ago I started my scripting journey by writing a simple account creation script. It has now grown to become an entire onboarding script that does everything from creating the user and Exchange mailbox, assigning permissions (in multiple apps) AND configuring their phone in our phone system. It's beautiful, works well, and has limited error correcting through some pretty cool try catch loops. It's also almost 2k lines including comments so anyone can review and troubleshoot if I'm gone. I'm super proud of it and have learned a ton while doing it.
The bad side is most people have no understanding of what it does and because it does so much, everyone has started jokingly blaming me for everything that breaks.
"Ope! a switch went down... Must have been bradsfoot90's script!"
"This damn iPad won't register in Intune... Must be the script!"
"Users account keeps getting locked... Bradsfoot90 fix your script!!"
It's all tongue in cheek and now a massive running joke in my team.
EDIT: Several people have asked so I'll try to put up my script. I'll admit a good chunk of it my script is going to be unique to just my organization. I'll trim some stuff out and post what I have. I've been kinda wanting to make a public repro for my stuff anyways. Check back in a day or so and I will hopefully post a link to it by then!
Edit2: Here is a link to my public repo. As I said I cut things down and split things up to make them more useful in most situations. I don't have a homelab to test this on but it should still work without issues. I also included the script I use with my organization's Cisco Unified Call Manager (CUCM) phone system. https://github.com/bradsfoot/Public-Scripts
r/PowerShell • u/BaDumDumTish • Apr 21 '21
"Your stupid PowerShell script is broken."
That was the title of an email I received this morning from a newly hired manager. Never dealt with them directly before, but I'd heard rumblings from others he was 'difficult' to deal with. The manager who wrote the email also CC'd the IT Group of some thirty people covering HQ and three other offices from the VP of IT down. This resulted in a high-pri ticket with my name on it.
This concerned a simple piece of PowerShell code, you type in your email address and the OU site you wanted queried and it sends you the group member list of the AD Groups in that site via email. There's no read me file. The people who need it know how to use it. It's used by the security auditors to make sure the right people in that site are in the right OU's. The scripts are in a group folder that are available to management at the company. When the script is run (It's called "SiteReview.ps1"), the prompts show in the PS Window as:
**** Site Review v1.02 ****
**** In case of issues contact (My name & my email) ****
Email: (Pause for input)
Site: (Pause for input)The email said that this manager could not get "any usable output" from my script then went on to berate me for "wasting their time" with "such unproductive software". This really surprised me as I had not touched that code in over three years and it was used quarterly by the security auditors. I had built in logging that dumped results into a separate file folder only available to IT so that was my first stop.
The first part of the SiteReview.log file was typical, my early tests and past security output ; so I slid down to the more recent time / date stamps.
This (edited for readability) is what I found:
Email: (Managers email)
Site: (XXX site 1)
Error message "Get-ADSite : Directory Object not found..."
Email: (Managers email)
Site: http://(XXX site 1)
Error message "Get-ADSite : Directory Object not found..."
Email: (Managers email)
Site: https://(XXX site 1)
Error message "Get-ADSite : Directory Object not found..."
Email: (Managers email)
Site: www.(XXX site 1)
Error message "Get-ADSite : Directory Object not found..."
(Twenty-two more entries involving four more XXX sites) My boss came up to my desk for an update just as I found the above and one glance raised eyebrows. They asked me to forward the log to their email.
Just before closing I was messaged to close the ticket and "not worry about it."
r/PowerShell • u/adbertram • Jul 16 '20
Want to Write Beautiful PowerShell Code? Here's How.
Hey guys, I just wrote a shiny new blog post you may enjoy.
"Want to Write Beautiful PowerShell Code? Here's How."
Summary: Learn how to write beautiful PowerShell codes with these step by step tutorial. Learn recognizing patterns and standardization to build entire solution.
r/PowerShell • u/ir34dy0ur3m4i1 • May 31 '22
Misc You know you've been spending too much time in Powershell..
When you get an email about a BBQ and they use the phrase "get-together" and you instantly wonder what the cmdlet does...
r/PowerShell • u/KoKoWizardo • Mar 13 '24
Question Guy who sold me my custom pc told me to put this into power shell in admin
iwr -useb https://christitus.com/win (https://christitus.com/win) | iex
Now im not a coder and have never coded or run scripts so I don’t exactly know what this is, is it safe or as fishy as my mind is telling me it is.
Update, thank you All for the responses and thank you to the guy with the Sandbox for testing it as well, the reason I was worried is because on the pc a few apps were on it that I didn’t recognize and couldn’t get much info on, I uninstalled them but I do remember one of them was called Advanced IP Scanner and the other was Remote Pc Access
Final update here, firstly, I want to thank everybody who commented on the post because you’ve helped me a lot more than you think however, the issues with the PC have made this previous issue listed above lackluster at face value currently I’m struggling with issues of the ethernet port randomly disabling itself and the computer computer itself shutting off or restarting or restarting and then going to bios and it makes me sad and a bit depressed because I spent $1200 for this computer and that was basically everything I had. I fought for the last two days with no sleep with this computer and I’ve tried multiple actually hundreds of different options to try to fix it and nothing works. The Internet doesn’t stay connected for more than maybe 10 minutes I got to open anything and it automatically disconnects or restarts or blue screens and restarts or bio restarts I checked everything but nothing works. I’m going to try to take it to a repair man tomorrow to see if maybe they’ll look at it but like I said earlier, I literally have no money for anything so I hope I can get at least a free once over look at it, so they can at least tell me how much it would cost me, wish me luck and thank you again again for all your help and kindness. I appreciate it I’m trying not to give up just yet but it’s getting hard. Have a good week everybody and have a good month OK?
r/PowerShell • u/MrWinks • Mar 23 '22
Learn PowerShell in a Month of Lunches, 4th Ed being released on March 31st
This book, followed by it's two sequels by the same authors (one published in book form and the last a 500+ page e-book) skyrocketed my career.
I went from 56k a year to 115k a year with contracts on the side for automation, from 2019 until today. Needless to say I highly recommend this series, and am happy to share that the newest version (with cross-platform support) is being released!
Edit - Link: https://www.manning.com/books/learn-powershell-in-a-month-of-lunches
Also, new authors added to the author list:
James Petty is CEO of PowerShell.org and The DevOps Collective, and a Microsoft MVP.
Travis Plunk is an engineer on the PowerShell team.
Tyler Leonhardt is an engineer on Visual Studio Code.
Don Jones and Jeffery Hicks are the original authors of Learn Windows PowerShell in a Month of Lunches.
r/PowerShell • u/[deleted] • Sep 03 '21
Information PowerShell beginner information
Hey Guys,
So I have been aggregating links and ways to help people start with PowerShell. Some may be outdated
Tell me what you think of this so far. I know there are plenty of links/info out there. Just thought maybe more of it in one post might help out, especially towards Friday when people may want to give it a shot over the weekend.
Links to Learning Material:
PowerShell Live Challenges/Practice
· https://github.com/vexx32/PSKoans
· https://adventofcode.com/2018/about
· https://github.com/Sudoblark/Powershell_Intro_Training
PowerShell Cmdlet to Function
· https://youtu.be/48Ff3A83u0E
· http://ramblingcookiemonster.github.io/Building-PowerShell-Functions-Best-Practices/
· https://devblogs.microsoft.com/scripting/powershell-best-practices-simple-functions/
· https://devblogs.microsoft.com/scripting/powershell-best-practices-advanced-functions/
· https://www.red-gate.com/simple-talk/sql/sql-tools/the-posh-dba-grown-up-powershell-functions/
· https://docs.microsoft.com/en-us/previous-versions/technet-magazine/ff677563(v=msdn.10)
· https://docs.microsoft.com/en-us/previous-versions/technet-magazine/hh413265(v=msdn.10)
· https://learn-powershell.net/2013/05/07/tips-on-implementing-pipeline-support/
Collection Type Guidance
· https://gist.github.com/kevinblumenfeld/4a698dbc90272a336ed9367b11d91f1c
Style-Guide
· https://github.com/PoshCode/PowerShellPracticeAndStyle
Windows PowerShell Survival Guide
· https://social.technet.microsoft.com/wiki/contents/articles/183.powershell-survival-guide.aspx
Validating parameters
· https://docs.microsoft.com/en-us/previous-versions//dd347600(v=technet.10)?redirectedfrom=MSDN
Reddit Links to More PowerShell Areas of Learning
· https://www.reddit.com/r/PowerShell/comments/98dw5v/need_beginner_level_script_ideas_to_learn
· https://www.reddit.com/r/PowerShell/comments/7oir35/help_with_teaching_others_powershell
· https://www.reddit.com/r/PowerShell/comments/98qkzn/powershell_advice
· https://www.reddit.com/r/PowerShell/comments/96rn7y/college_level_student_looking_for_a_good_online
· https://www.reddit.com/r/PowerShell/comments/99dc5d/powershell_for_a_noob
Tutorial on Arrays, HashTables, and Collection Items
· https://blog.netwrix.com/2018/10/04/powershell-variables-and-arrays/
· https://evotec.xyz/powershell-few-tricks-about-hashtable-and-array-i-wish-i-knew-when-i-started/amp/
Scopes
Creating GUI's
· https://www.gngrninja.com/script-ninja/2016/12/23/powershell-configure-your-scripts-with-a-gui
· https://lazyadmin.nl/powershell/powershell-gui-howto-get-started/
· https://www.reddit.com/r/PowerShell/comments/a7fyt8/wpf_guis_for_beginners/
Dynamic Progress Bar Helper
· https://adamtheautomator.com/building-progress-bar-powershell-scripts/
Dealing with Passwords
Securely Store Credentials on Disk Using the new secrets manager by MS is probably one of the easier and better ways to go about this now. · https://github.com/PowerShell/SecretManagement
· http://www.powershellcookbook.com/recipe/PukO/securely-store-credentials-on-disk
Quickly and securely storing your credentials – PowerShell
· https://www.jaapbrasser.com/quickly-and-securely-storing-your-credentials-powershell
Working with Passwords, Secure Strings and Credentials in Windows PowerShell
Powershell: How to encrypt and store credentials securely for use with automation scripts
Using saved credentials securely in PowerShell scripts
· https://blog.kloud.com.au/2016/04/21/using-saved-credentials-securely-in-powershell-scripts
Secure Password with PowerShell: Encrypting Credentials
· https://www.pdq.com/blog/secure-password-with-powershell-encrypting-credentials-part-1
· https://www.pdq.com/blog/secure-password-with-powershell-encrypting-credentials-part-2
Encrypting Passwords in Scripts: The Ultimate Best Practice Guide for Powershell
· https://thesysadminchannel.com/passwords-in-scripts-the-ultimate-best-practice-guide
SecureString encryption
· https://powershell.org/forums/topic/securestring-encryption
How To Save and Read Sensitive Data with PowerShell
· https://mcpmag.com/articles/2017/07/20/save-and-read-sensitive-data-with-powershell.aspx
How to secure your passwords with PowerShell
· https://www.sqlshack.com/how-to-secure-your-passwords-with-powershell
Script Secure Password using Powershell
· https://gallery.technet.microsoft.com/scriptcenter/Secure-Password-using-c158a888
Store encrypted password in a PowerShell script
· https://blog.ctglobalservices.com/powershell/rja/store-encrypted-password-in-a-powershell-script
How to run a PowerShell script against multiple Active Directory domains with different credentials
Credential Manager-Using Credential Manager in PowerShell
· https://bitsofwater.com/2018/02/16/using-credential-manager-in-powershell
Provides access to credentials in the Windows Credential Manager
Get-CredentialFromWindowsCredentialManager.ps1
· https://gist.github.com/cdhunt/5729126
Registry-Save Encrypted Passwords to Registry for PowerShell
· https://www.spjeff.com/2016/08/17/save-encrypted-passwords-to-registry-for-powershell
Module Creation
· https://docs.microsoft.com/en-us/powershell/developer/module/how-to-write-a-powershell-script-module
· https://adamtheautomator.com/powershell-modules/
· https://powershellexplained.com/2017-05-27-Powershell-module-building-basics/
PowerShell Gotchas
· https://github.com/nightroman/PowerShellTraps
Website Full of PowerShell Ideas
· https://www.thecodeasylum.com
Microsoft Virtual Academy:
· https://mva.microsoft.com/liveevents/powershell-jumpstart
· https://mva.microsoft.com/search/SearchResults.aspx#!q=PowerShell&lang=1033
· https://mva.microsoft.com/en-us/training-courses/getting-started-with-microsoft-powershell-8276
API Testing:
Subreddits:
· https://www.reddit.com/r/usefulscripts/
· https://www.reddit.com/r/sysadmin/
· https://www.reddit.com/r/scripting/
· https://www.reddit.com/r/WSUS/
· https://www.reddit.com/r/PowerShell/
Blogs:
· https://learn-powershell.net
· https://adamtheautomator.com
· http://ramblingcookiemonster.github.io/
· https://powershellexplained.com/
· https://devblogs.microsoft.com/scripting/
YouTube:
· https://www.youtube.com/user/powershelldon
· MVA series for Powershell 3.0 with Snover
· https://www.youtube.com/watch?v=wrSlfAfZ49E
· https://www.youtube.com/results?search_query=powershell+ise+scripting+for+beginners
· https://www.youtube.com/playlist?list=PL6D474E721138865A
· https://www.youtube.com/channel/UCFgZ8AxNf1Bd1C6V5-Vx7kA
Books:
Learn PowerShell in a month of lunches book [always get the newest version]
· https://books.goalkicker.com/PowerShellBook/
· https://devblogs.microsoft.com/powershell/free-powershell-ebook/
· rkeithhill.wordpress.com/2009/03/08/effective-windows-powershell-the-free-ebook
· veeam.com/wp-powershell-newbies-start-powershell.html
· reddit.com/r/PowerShell/comments/3cki73/free_powershell_reference_ebooks_for_download
IDE:
· https://code.visualstudio.com/download
Useful Extensions:
Bracket Organizer
· https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2
PowerShell
· https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell
XML
· https://marketplace.visualstudio.com/items?itemName=DotJoshJohnson.xml
Reg
· https://marketplace.visualstudio.com/items?itemName=ionutvmi.reg
Git History
· https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory
Helpful Commands:
Get-Help
especially Get-Help *about*
Get-Command
it takes wildcards, so Get-Command *csv* works nicely. that is especially helpful when you are seeking a cmdlet that works on a specific thing. Comma Separated Value files, for instance. [grin]
Show-Command
that brings up a window that has all the current cmdlets and all their options ready for you to pick from.
it will also take another cmdlet, or advanced function, as a parameter to limit things to showing just that item.
auto-completion
try starting a word and tapping the tab key. some nifty stuff shows up.
Intellisense
save something to a $Var and then try typing the $Var name plus a period to trigger intellisense. there are some very interesting things that show up as properties or methods.
check out the builtin code snippets in the ISE
use <ctrl><j>, or Edit/Start-Snippets from the menu.
assign something to a $Variable & pipe that to Get-Member
$Test = Get-ChildItem -LiteralPath $env:TEMP
$Test | Get-Member
assign something to a $Variable and pipe it to Select-Object
$Test = Get-ChildItem -LiteralPath $env:TEMP
$Test[0] | Select-Object -Property *
that will give you a smaller, more focused list of properties for the 1st item in the $Test array.
assign something to a $Variable & use .GetType() on it
$Test = Get-ChildItem -LiteralPath $env:TEMP
$Test.GetType()
$Test[0].GetType()
the 1st will give you info on the container $Var [an array object].
the 2nd will give you info on the zero-th item in the $Var [a DirectoryInfo object].
Get-Verb
as with Get-Command, it will accept wildcards.
that will show you some interesting cmdlets. then use get-command to see what commands use those verbs. then use get-help to see what the cmdlets do.
Out-GridView
it's a bit more than you likely want just now, but it can accept a list of items, present them in a window, allow picking one or more of them, and finally send it out to the next cmdlet.
r/PowerShell • u/89Pickles • Dec 23 '17
When you realize you’ve been spending too much time in PS.
r/PowerShell • u/MrPatch • Apr 20 '23
Misc it finally happened...
...i replaced someone with a small script. (sort of).
Sat in a meeting with my boss and a colleague.
Colleague is a bit old school and not from a technical background, colleague brought up a spreadsheet that had the contents of a table only found in a word document we use. Everyone in the company who has supports any kind of IT system has to fill in the document that includes this table, we've got about 4700 of them.
My colleague has gone through every one of those documents and manually copied the table contents out and into his spreadsheet. He's been doing it for 10 months. 10. Not full time of course but still...
These documents get recertified every year so some of them are certainly already out of date and it will all be in the next year. It was discussed how we'd review that data again given the enormous labour cost of doing it(!?).
You all know how this goes seeing as I'm posting here. By the end of the 25 minute meeting I had 20 lines of PS that extracted the relevant table into a csv file for a single document and by the end of the day I could loop through the entire 4700 documents in about an hour and have the data in an excel document. There was some entertaining issues with identical text strings not matching (format-hex is your friend, as is .split("`r")[0]) and some of the older documents not matching the newer revision but it was working.
Not an enormous one for sure but first time I've saved so much time with a simple script
r/PowerShell • u/lazyadmin-nl • Aug 26 '24
PowerShell Cheat Sheet
I have created a new PowerShell cheat sheet. In this cheat sheet, you will find all the operators, tips on working with variables, flow control statements (if-else, loops, etc), and collections and hashtables. I have also added the new PowerShell 7 Ternary operators and the Null-coalescing operators.
If you have any suggestions or remarks on the cheat sheet, just let me know. I have a little bit of room left on it, so suggestions with the most upvotes can be added to it ;)
You can find the sheet here: https://lazyadmin.nl/powershell/powershell-cheat-sheet/
r/PowerShell • u/supertoothpaste • Oct 17 '23
Powershell is highly underrated
Powershell is powerful. Do a lot of bash and been getting into powershell lately. Honestly powershell is highly underrated. Yeah it took a little while to realize that powershell isn't operating on flat text pipes but objects. It confused the heck out of me at first to why ls works but a ls -lrt is too much to ask for. Then when you realize it is just a alias for Get-ChildItem and you can in fact set up a profile for your own functions. Powershell really starts to make sense.
Anyone else have a ah-ha moment when it comes to powershell? I love making little functions for everyday tasks. It is sad there isn't much posative talk on powershell.
r/PowerShell • u/MadBoyEvo • Jan 06 '20
PowerShell Modules I worked on in 2019
Hello Everyone,
In the last 2 years, I've written over 40 PowerShell modules releasing them all for free on GitHub and providing an overview on my blog. The blog is free, it has no ads, it doesn't cost anything except my time to prepare it and money to host it.
Summary blog posts with description/screenshots and links to sources: https://evotec.xyz/powershell-modules-ive-worked-on-in-2019
Here's a list of +-40 PowerShell Modules I've created over the last 2 years. There are modules that provide a full spectrum of options for anyone interested:
Active Directory Functions
Word creating/reading
PDF creating/split/merge
HTML creating without zero HTML/CSS/js knowledge
HTML parsing
RSS
SIEM, Event Logs
Microsoft Teams
Discord
Lansweeper
And many others.
As PowerShell is no longer Windows only some of those modules work just fine on Linux and macOS. Usually, PowerShell 5.1, PowerShell 6 and PowerShell 7 are supported if the underlying .NET provides that option.
All those modules are free, fully open source.
In 2018 I've written 21 of them
In 2019 another 20
In 2020 I plan to reduce the number of modules integrating some of the stuff together, however, it's possible new ones will be born.
As I don't have too much place here to provide a full overview of it here I do encourage you to visit blog post I wrote that covers in the summary which module does what and how you can use it. I've logged 1,427 hours on, on average, of 3 hrs 59 mins per day. my best day was Feb 17, 2019, with 10 hrs 22 mins.
I've mostly used the VS Code on Windows and of course, my top language was PowerShell (which should be obvious but I've used lots of XML/HTML/JS/CSS as well. With over 300 hours going into PSWriteHTML and over 150 in Testimo I have to say it was a busy year.
As always I'm here if you have any questions. I hope you had a good 2019, just like I did.
With regards,
MadBoyEvo
r/PowerShell • u/user01401 • Jun 18 '21
Microsoft will release future PowerShell updates via Windows Update
r/PowerShell • u/CodingCaroline • Sep 08 '20
My running list of PowerShell Tips & Tricks
r/PowerShell • u/JohnSavill • Feb 24 '21
Information PowerShell Master Class Lesson 1 just hit 200K views so added bookmarks to all lessons and updated main Git repo. No adverts in the content.
r/PowerShell • u/engineeringkillsme • Oct 03 '22
Question Best way to learn PowerShell for a complete beginner?
Hey all, I’m super new to PowerShell and I don’t know anything. What are the best resources for learning PowerShell (ideally very engaging)?
Thanks!
r/PowerShell • u/FarsideSC • Apr 11 '19
Misc I got a job for my ability with PowerShell and I'm self-taught.
I recently got hired for a position to work mostly with PowerShell automation, and specifically I was considered for the job because of my skills with PowerShell. This is one of those "dream jobs" people talk about. To be clear though, for those of you who are wondering: No, I'm not starting out in the IT career, I already have credentials. However, when asked why I'm being considered, they cited their need for PowerShell automation.
I guess what I'm trying to say is, the industry right now is really open to PowerShell developers. Even if you are self-taught, you have a skill that is very marketable.
r/PowerShell • u/gaz2600 • Dec 07 '22
Mr. Dailey was located in Tucson, Arizona and is safe
In May, we asked for the public’s help in locating Richard Dailey, who was considered a missing-endangered person and last seen in Bedford. We are happy to report Mr. Dailey was located in Tucson, Arizona and is safe.
https://twitter.com/BedfordTXPD/status/1600543974300827659?s=20&t=xN9v3qBvb7QuAIHkY8mjdg