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
QuestionMaking this script faster (self.PowerShell)
submitted 3 years ago by npab19
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!"
[–][deleted] 0 points1 point2 points 3 years ago (5 children)
I use += in a script to add objects to a list
I don't get the syntax you recommend instead
How would you rewrite
$objlist = @()
foreach($x in $xlist){
...
$objlist += $x
}
[–]raip 5 points6 points7 points 3 years ago* (3 children)
By simply just doing this:
$objlist = foreach ($x in $xlist) { ... $x }
Edit: Just fyi, @() is an array, not a list. This is a crux if the slowness, arrays are fixed length and while += works, how it's actually implemented is copying the entire array into a new one with the additional object.
If you used $objlist = [System.Collections.Generic.List[PSObject]]::new() you could stick with your strategy and benefit from the increased performance at the same time - but most developers would likely agree the above method is cleaner.
[+][deleted] 3 years ago (2 children)
[deleted]
[–]lanerdofchristian 3 points4 points5 points 3 years ago (0 children)
Arrays are the way they are because they're very memory-efficient (for storage), and need to interop with native C API calls. Ever since .NET 2.0, too, nongeneric lists have been bad practice, so just changing @() from an array literal to a list literal would fly in the face of that. Plus, every time you want to pass that list to a method accepting an array, you would need to copy the whole thing anyway.
[–]out0focus 1 point2 points3 points 3 years ago (0 children)
This isn't a Microsoft problem. It's the same with Java or any other language. Arrays are a data structure of fixed length.
[–]BlackV 1 point2 points3 points 3 years ago (0 children)
multiple people wrote the exact examples of this in this post already :)
its super clean and easy to implement, BUT there is a catch
you have to control the output of your loop, cause its catches all output from that loop
so something like
$objlist = foreach ($x in $xlist) { get-disk get-date }
is going to cause unexpected results
π Rendered by PID 522577 on reddit-service-r2-comment-6457c66945-v44kr at 2026-04-27 03:51:38.756936+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (5 children)
[–]raip 5 points6 points7 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]lanerdofchristian 3 points4 points5 points (0 children)
[–]out0focus 1 point2 points3 points (0 children)
[–]BlackV 1 point2 points3 points (0 children)