PowerShell Trust Error: Your Ultimate 2025 Fix Guide
Stuck on the PowerShell 'Untrusted Repository' error? Our 2025 guide explains why it happens and provides clear, safe fixes—from quick one-liners to best practices.
David Miller
A Senior DevOps Engineer and PowerShell MVP passionate about automation and secure scripting.
You’re in the zone. You’ve mapped out your script, you know exactly which module you need from the PowerShell Gallery, and you type Install-Module
with the confidence of a seasoned pro. Then, it happens. A wall of red text floods your console, centered around a single, frustrating message: "Untrusted repository."
It’s an error that has stopped countless developers and sysadmins in their tracks. Your first instinct might be to search for a quick one-liner to make it go away. And while those exist, blindly running them without understanding *why* the error occurs is like turning off a smoke alarm because you don't like the noise. That error isn't a bug; it's a crucial security feature designed to protect you.
In this ultimate 2025 guide, we'll demystify the PowerShell trust error once and for all. We’ll dive into what it means, why it’s there, and walk through a full spectrum of solutions—from the quick and dirty to the safe and sustainable. By the end, you'll not only fix the error but also understand how to manage PowerShell repositories like an expert.
What Exactly Is the PowerShell Trust Error?
At its core, the "Untrusted repository" error is PowerShell's way of asking, "Are you sure you want to install software from this online source?" The default and most common PowerShell repository is the PSGallery, a public gallery of scripts and modules maintained by Microsoft. It's an incredible resource, but because it's a public source, PowerShell wants you to explicitly acknowledge that you trust it before it will download and execute code from it.
Out of the box, PowerShell is configured with a "trust but verify" mindset. It knows about the PSGallery but flags it as Untrusted
by default. This forces you, the user, to make a conscious decision. This security posture helps prevent supply-chain attacks, where a malicious actor might try to trick you into connecting to a fake repository and downloading harmful code.
The Root Cause: Understanding Repositories
To solve the problem, we need to understand the moving parts. The issue isn't with your script or the module you want; it's with the relationship between your local PowerShell instance and the remote repository.
You can see your configured repositories by running this command:
Get-PSRepository
You'll likely see an output similar to this:
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2
The key here is the InstallationPolicy
column. The status Untrusted
is what triggers the error prompt every time you try to use Install-Module
, Update-Module
, or Save-Module
. Our goal is to manage this policy effectively.
The Quick Fix (And Why You Should Be Cautious)
If you've searched for this error before, you've probably seen this command recommended as the instant solution:
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Running this command will, indeed, stop the error from appearing. It works by changing the InstallationPolicy
for the PSGallery from Untrusted
to Trusted
for your current user account. After running it, Get-PSRepository
will show the policy as Trusted
, and subsequent installs will proceed without a prompt.
So what's the catch? While this is generally safe for the official PSGallery, it builds a bad habit. You're telling PowerShell to permanently and silently trust this source. If your configuration was ever hijacked to point to a malicious URL, PowerShell would happily download from it without asking. That's why it's better to use one of the more nuanced approaches below, at least until you're comfortable with the security implications.
The Better, Safer Solutions for 2025
Modern PowerShell workflows call for a more deliberate approach. Here are the best ways to handle the trust error, from most granular to most permanent.
Step 0: Verify Before You Trust
Before you change any settings, make sure your PSGallery repository is pointing to the correct, official URL. Run Get-PSRepository
and check that the SourceLocation
is https://www.powershellgallery.com/api/v2
. If it points somewhere else, you have a bigger problem and should investigate immediately rather than trusting it.
Solution A: The Per-Command Trust (-Force)
If you only need to install a module occasionally and want to maintain the highest level of security, the -Force
parameter is your best friend.
Install-Module -Name Pester -Force
The -Force
parameter tells PowerShell, "For this command only, I am overriding the trust check and installing the module." It doesn't change the repository's underlying InstallationPolicy
. It's the most secure way to interact with an untrusted repository because you're explicitly approving each and every transaction.
- Pros: Maximum security, no permanent changes.
- Cons: Repetitive. You have to remember to add
-Force
every time.
Solution B: The Interactive Prompt ("Yes to All")
What happens if you don't use -Force
? PowerShell will prompt you:
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet.
Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
This prompt is your friend! Here's what the most important options mean:
[Y] Yes
: Approves the installation for this single module. If the installation involves dependencies, you'll be prompted again for each one.[A] Yes to All
: This is the magic option. It approves the installation for the current module and all subsequent modules from this repository for the remainder of your PowerShell session. It does not permanently change the trust setting.
Using [A] Yes to All
is a fantastic middle ground. It's convenient for a session where you know you'll be installing multiple modules, but it resets to the secure default once you close the console.
Solution C: The Permanent Trust (Recommended Method)
If you are an active PowerShell user and frequently interact with the PSGallery, permanently trusting it is a reasonable and efficient workflow. It's the same command as the "Quick Fix," but now you're running it with full knowledge of what it does.
To trust the PSGallery for your user account only:
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
If you have administrative rights and want to trust the PSGallery for all users on the system, you can use the -Scope
parameter:
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -Scope AllUsers
This is the most convenient option for developers and administrators who have verified their repository source and accept the minimal risk associated with trusting the official Microsoft-run gallery.
Comparison: Which Fix is Right For You?
Here's a quick summary to help you choose the best method for your needs.
Method | Best For | Security Level | Convenience |
---|---|---|---|
-Force Parameter |
One-off installations, highly secure environments | Very High | Low |
Interactive Prompt [A] Yes to All |
Installing several modules in a single session | High | Medium |
Set-PSRepository ... Trusted |
Regular PowerShell users, developers, and admins | Good | High |
Troubleshooting Further Issues
What if you've set the repository to Trusted
but still face issues? Here are a couple of things to check:
- Corporate Policies: In an enterprise environment, your system may be governed by Group Policy Objects (GPOs) that override your local settings. Your PowerShell Execution Policy might also be restricted. Run
Get-ExecutionPolicy
to check. - Network Issues: A firewall or proxy server could be blocking access to
powershellgallery.com
. Try a simple command likeInvoke-RestMethod -Uri https://www.powershellgallery.com/api/v2
to see if you can reach the server.
Conclusion: Script with Confidence
The PowerShell "Untrusted repository" error is not a roadblock; it's a guardrail. By understanding that it's a deliberate security feature, you can move from being frustrated by it to being empowered by it. You now have a complete toolkit to handle it, whether you prefer the cautious, command-by-command approach or the efficient, set-it-and-forget-it method for trusted sources.
So the next time you see that prompt, you'll know exactly what to do—and why you're doing it. Now, go ahead and install that module with confidence!