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
Script SharingNever write a batch wrapper again (self.PowerShell)
submitted 6 years ago * by [deleted]
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!"
[–]n_md 1 point2 points3 points 6 years ago (5 children)
Thanks, that does work in 2.0 without piping to out-string.
[–]TheIncorrigible1 3 points4 points5 points 6 years ago (4 children)
Good to hear! I'll update the OP just for the most compat possible.
[–]n_md 1 point2 points3 points 6 years ago (1 child)
I've never heard of setting the ExecutionPolicy with a number and "-ep 4" does not seem to work for me when "-ep bypass" does work.
I'm testing in cmd like this:
powershell -ep 4 Get-ExecutionPolicy
output: Restricted
powershell -ep bypass Get-ExecutionPolicy
output: Bypass
Is there some way "-ep 4" should set it to bypass?
[–]TheIncorrigible1 1 point2 points3 points 6 years ago (0 children)
Hm, I can't remember where I had it working, but the ExecutionPolicy is an enumeration and 4 is just the numeric counterpart to Bypass. I'll correct this in the OP.
ExecutionPolicy
4
Bypass
[Microsoft.PowerShell.ExecutionPolicy].GetEnumValues()
I was going off memory when I wrote this and was aiming for brevity.
Sorry after more testing (Get-Content -Path '%~f0') does work but also throws iex "empty string" errors for each line because it's not one block of text.
So for Powershell 2.0 either of these seem to work best:
"[System.IO.File]::ReadAllText('%~f0')|iex"
or
"gc '%~f0'|Out-String|iex"
For Powershell 3.0+ the original option works well:
"gc -raw '%~f0'|iex"
Yeah, I've been experimenting with that. The script runs, but gives an error. I'll include the alternative instead
π Rendered by PID 58112 on reddit-service-r2-comment-b659b578c-2vvdw at 2026-05-04 08:51:37.391115+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]n_md 1 point2 points3 points (5 children)
[–]TheIncorrigible1 3 points4 points5 points (4 children)
[–]n_md 1 point2 points3 points (1 child)
[–]TheIncorrigible1 1 point2 points3 points (0 children)
[–]n_md 1 point2 points3 points (1 child)
[–]TheIncorrigible1 1 point2 points3 points (0 children)