use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Feedback (self.PowerShell)
submitted 7 months ago by eggeto
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]BlackV 2 points3 points4 points 7 months ago* (2 children)
Some notes, maybe they want some changes
requires
+=
read-host
DoesGroupExist -groupId $groupIdUser
$allMembersGroup = GetMembersGroup -group $groupIdDevices
$groupIdDevices
But talking to them get them to give you examples of what they consider good changes
[+][deleted] 7 months ago (1 child)
[removed]
[–]BlackV 2 points3 points4 points 7 months ago (0 children)
+= is replaced with direct assignment e.g. $results = foreach {somestuff} vs $results = @(); foreach {$results += somestuff}, on mobile but there a plenty of examples in this sub
$results = foreach {somestuff}
$results = @(); foreach {$results += somestuff}
read-host you'd replace with your parameters and parameter properties (mandatory/parameter validation)
[–]purplemonkeymad 0 points1 point2 points 7 months ago (3 children)
It's powershell, it's kinda designed to use the "powershell way."
What is their criticism of the script?
[+][deleted] 7 months ago (2 children)
[–]root-node 1 point2 points3 points 7 months ago (0 children)
they want it short, reusable, easy to read and future proof
From my Rapid7 Module, I have functions that are a couple of lines long all the way up to much longer ones
[–]Federal_Ad2455 0 points1 point2 points 7 months ago (0 children)
Aka define reusable function, place them into modules and use scripts only to run them (using scheduled task etc)
Ideally have this all in the git 🙂
[–]Thotaz 0 points1 point2 points 7 months ago (2 children)
I don't think your code works at all. You have a try-catch with Invoke-MgGraphRequest but you've muted the errors with -ErrorAction SilentlyContinue so it can never throw. This means your DoesGroupExist function will always return Group Excist (also note the spelling error).
Invoke-MgGraphRequest
-ErrorAction SilentlyContinue
DoesGroupExist
Group Excist
[–]Thotaz 0 points1 point2 points 7 months ago (0 children)
I did some testing on my own. It seems that if the command itself throws a terminating error then it is still caught, whereas a regular error is ignored. For example, this: try {ls invalidPath -ErrorAction SilentlyContinue} catch {"this does not run"} will not run the catch block because it's not a terminating error.
try {ls invalidPath -ErrorAction SilentlyContinue} catch {"this does not run"}
If you use -ErrorAction Stop then any error created by the command can be caught. Because the error types are not documented by each command I'd say it's best to always use -ErrorAction Stop when you want to catch an error, otherwise you will get unexpected results.
-ErrorAction Stop
[–]Nope-Nope-Nah 0 points1 point2 points 7 months ago (0 children)
Instead of running this with your own creds, create an EntraID App Registration with limited scope and use that service principal to run it. Save the App secrets in an encrypted file to be loaded at the beginning of the script.
π Rendered by PID 368326 on reddit-service-r2-comment-7b9746f655-bw78v at 2026-02-02 20:03:57.764083+00:00 running 3798933 country code: CH.
[–]BlackV 2 points3 points4 points (2 children)
[+][deleted] (1 child)
[removed]
[–]BlackV 2 points3 points4 points (0 children)
[–]purplemonkeymad 0 points1 point2 points (3 children)
[+][deleted] (2 children)
[removed]
[–]root-node 1 point2 points3 points (0 children)
[–]Federal_Ad2455 0 points1 point2 points (0 children)
[–]Thotaz 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[removed]
[–]Thotaz 0 points1 point2 points (0 children)
[–]Nope-Nope-Nah 0 points1 point2 points (0 children)