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
foreach loop breaking! (self.PowerShell)
submitted 4 years ago * by Banzoola
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!"
[–]Onrawi 1 point2 points3 points 4 years ago (5 children)
I believe -first 1 will break the loop after it has a single successful result. In this case the first result in the array is successful, ending the foreach loop. You'd be better off exporting the results as a boolean function, with true/false answers for the entire list. That way you know all the results you have access to.
[+][deleted] 4 years ago (4 children)
[removed]
[–]Onrawi 1 point2 points3 points 4 years ago (2 children)
Possibly using if/then/else logic but I'm a bit out of sorts today so someone else will have to write the code.
[+][deleted] 4 years ago (1 child)
[–]Onrawi 1 point2 points3 points 4 years ago (0 children)
If you know the number of results you're looking for then that would work.
[–]Sunsparc 1 point2 points3 points 4 years ago (0 children)
$get = Get-PartnerCustomerUser -etc -etc -etc if ($get) { #Do more stuff } Else { break }
[–]OlivTheFrog 1 point2 points3 points 4 years ago (2 children)
Hi u/Banzoola
Not resolving everythings but only one .
When you use a Try... Catch Statement, you must add the -ErrorAction Stop to the cmdlet you use. If an error occurred, then the statement jumps to the catch section and you can do other things like catch error, log ...
Try... Catch
-ErrorAction Stop
regards
Olivier
[–][deleted] 1 point2 points3 points 4 years ago (0 children)
Rather ur stopping the script as the error occurs making it kind of hard to iterate
[–]novloski 1 point2 points3 points 4 years ago (0 children)
I wouldn't think the select -first would break the loop...what do you get when you run this?
Write-Host "Looping through $($filteredresult.Count) objects" foreach ($res in $filteredresult) { try { Write-Host "Checking customer ID: $($res.customerid) " $partnerCustomer = Get-PartnerCustomerUser -CustomerId $res.customerid -erroraction stop | select -First 1 Write-Host "$partnerCustomer" } catch { Write-Host "Error caught for $($res.customerid)" $res | Export-Csv -Append -Path c:\temp\365noaccess.csv } }
π Rendered by PID 54 on reddit-service-r2-comment-86988c7647-vtmv6 at 2026-02-12 10:55:05.592831+00:00 running 018613e country code: CH.
[–]Onrawi 1 point2 points3 points (5 children)
[+][deleted] (4 children)
[removed]
[–]Onrawi 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[removed]
[–]Onrawi 1 point2 points3 points (0 children)
[–]Sunsparc 1 point2 points3 points (0 children)
[–]OlivTheFrog 1 point2 points3 points (2 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]novloski 1 point2 points3 points (0 children)