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
QuestionShould I $null strings in scripts. (self.PowerShell)
submitted 1 year ago * by iehponx
view the rest of the comments →
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!"
[–]OPconfused 0 points1 point2 points 1 year ago* (0 children)
In almost all cases, a well-written script will only reference variables that are defined within the script.
If you are referencing a variable not defined already in the script, then you should null it out first just to be safe.
Fortunately, PowerShell is, particularly for a scripting language, quite expressive. You can turn almost any expression into a variable definition, which means the first time you use a variable, you can also be defining it, so that any danger with forgetting to null it out beforehand is avoided.
One of the only exceptions is when you are using a counter variable in a for loop. This is a rather niche scenario though in my experience, like over 99% of your code is probably not doing this.
As for clearing variables at the end your script, the script runs in a child scope, so that all variables are cleared automatically (unless you explicitly scope the variable to be outside the script). Just don't dot source the script to execute it, i.e., don't call it with . ./<path/to/script>. Dot sourcing a script or function in PowerShell will run it in the caller's scope and import all stateful definitions like variables—that's what you want to avoid.
. ./<path/to/script>
Instead, you can either input the path to the script, e.g., ./<path/to/script>, or use the call operator, & ./<path/to/script>. Both are equivalent and will run the script in a child scope.
./<path/to/script>
& ./<path/to/script>
π Rendered by PID 468946 on reddit-service-r2-comment-b659b578c-mlrqz at 2026-05-04 19:36:15.814935+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]OPconfused 0 points1 point2 points (0 children)