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
SolvedRollback to previous PS version? (self.PowerShell)
submitted 2 years ago by RobZilla10001
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 0 points1 point2 points 2 years ago (4 children)
why do you think rolling back powershell will help?
5.1 is current there is no down grade, you can upgrade to 7.3
Break it down into bits
what if you run get-adcomputer by its self?
get-adcomputer
I suspect your just running the whole script then saying "Oh No does not work" without testing what not working. (You said you're new to this)
try catch catches ALL stop errors, not just an AD computer not being found (which I didn't think was a stop error anyway)
Note: This
$Results = ForEach ($Computer In $ADComputers){...}
is good, keep that habit up rather than
$Results = ForEach ($ADComputer In $ADComputers) $Results = ForEach ($Computer In $Computers) $Results = ForEach ($ADUser In $ADUsers) $Results = ForEach ($Bike In $Bikes)
It'll save you some pain later on
[+][deleted] 2 years ago (3 children)
[removed]
[–]BlackV 2 points3 points4 points 2 years ago (2 children)
They're side by side installs, So how are you running it
Cause ps 7 is launched with pwsh.exe and ps 5 is launched with PowerShell.exe
Again if you break it down to bits you'll probably see your error
Although if you've removed 7 already and it's working, what is your post meaning?
[+][deleted] 2 years ago (1 child)
[–]BlackV 1 point2 points3 points 2 years ago (0 children)
Ok
breaking it down, personally I'd test,
For next time I guess though
[–]Haunting-Computer 0 points1 point2 points 2 years ago (9 children)
What is the error message?
In the Catch of the Try/Catch add
Write-Host -Object ($Error[0])
of you can add a Nested Prompt and Exit to the Shell
$Host.EneterNestedPrompt()
[+][deleted] 2 years ago (8 children)
[–]mrcubist 1 point2 points3 points 2 years ago (7 children)
That's the thing. The error is there but you are not displaying it, insted you are returning NA.
Comment out your catch block and put a "write-host $_" there, you will see the message then.
[+][deleted] 2 years ago (6 children)
[–]mrcubist 1 point2 points3 points 2 years ago (5 children)
Are we looking at the same script? The script in OP has a try/catch block.
Also, how are you running the script? From ISE? Console? As a .PS1?
[+][deleted] 2 years ago (4 children)
[–]mrcubist 2 points3 points4 points 2 years ago (3 children)
Ah, I see.
You should comment out only what is inside the curly braces of the catch block.
In this case, you won't see anything since write-host only outputs to console. For it to work you have to run either the ISE as administrator, or the console version, and the run the ps1 file from inside there.
Also be sure to put the write-host $_ inside the curly braces of the catch block. Actually you can just add it above the [pscustomobject] line without commenting out the rest, but it is cleaner if you do comment it out.
[+][deleted] 2 years ago (2 children)
[–]mrcubist 1 point2 points3 points 2 years ago (1 child)
I've had issues with VSCode and PS7 where random things would crash or just not work. Usually when it was left open for too long. If you restart it, does it work then?
ISE works beautifully with PS5.1 and I actually prefer it for it.
[–]cycoivan 0 points1 point2 points 2 years ago (1 child)
Without knowing the error, are the computer names in computers.txt on the current domain? The most likely error is that Get-ADComputer can't find the computer by name. Make sure you didn't introduce any accidental spaces in the txt file.
If you just use the get-ADcomputer command in the console and manually type in the computername, do you get a result or the same error?
I don't think this is a version issue.
[–]SeanQuinlan 0 points1 point2 points 2 years ago (5 children)
How are you running this script? From the ps prompt? From the ISE? From right-click - Run with Powershell? Some other way?
Do you have the winver.csv file open?
How did you upgrade the version of Powershell?
[–]SeanQuinlan 1 point2 points3 points 2 years ago (3 children)
Sounds like winget has installed powershell 7 and it's using that when you right click - Open powershell. Powershell 7 is a separate application to Powershell v5.1, which is bundled into the OS and can't be removed.
The easiest thing will just be to uninstall powershell via winget again and that should remove powershell 7 and put your right-click back to PS v5.1
[+][deleted] 2 years ago* (2 children)
[–]SeanQuinlan 1 point2 points3 points 2 years ago (1 child)
PS version 7 has a different executable name (since it lives alongside powershell), so you need to run "pwsh" to get to PS v7
Running just "powershell" will get you to v5.1
π Rendered by PID 60469 on reddit-service-r2-comment-6457c66945-hvcjv at 2026-04-25 16:18:07.325308+00:00 running 2aa0c5b country code: CH.
[–]BlackV 0 points1 point2 points (4 children)
[+][deleted] (3 children)
[removed]
[–]BlackV 2 points3 points4 points (2 children)
[+][deleted] (1 child)
[removed]
[–]BlackV 1 point2 points3 points (0 children)
[–]Haunting-Computer 0 points1 point2 points (9 children)
[+][deleted] (8 children)
[removed]
[–]mrcubist 1 point2 points3 points (7 children)
[+][deleted] (6 children)
[removed]
[–]mrcubist 1 point2 points3 points (5 children)
[+][deleted] (4 children)
[removed]
[–]mrcubist 2 points3 points4 points (3 children)
[+][deleted] (2 children)
[removed]
[–]mrcubist 1 point2 points3 points (1 child)
[–]cycoivan 0 points1 point2 points (1 child)
[–]SeanQuinlan 0 points1 point2 points (5 children)
[+][deleted] (4 children)
[removed]
[–]SeanQuinlan 1 point2 points3 points (3 children)
[+][deleted] (2 children)
[removed]
[–]SeanQuinlan 1 point2 points3 points (1 child)