Repository navigation
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
- Install PowerShell 7.4.0
- Start it
- Create a
powershell.config.jsonand setPSModulePathto multiple paths, separated by;(path separator char) (see reference). - See it fail
Expected behavior
It starts, like 7.3 did.
Actual behavior
It fails with:
PowerShell 7.4.0
The shell cannot be started. A failure occurred during initialization:
Index was out of range. Must be non-negative and less than or equal to the size of the collection. (Parameter 'startIndex')
Error details
Not possible.
Environment data
Not possible, but it is version 7.4.0.
Visuals
This is starting from Nushell:
This is starting it from Windows Terminal:
Additional context
Downloaded and installed this file: https://github.com/PowerShell/PowerShell/releases/download/v7.4.0/PowerShell-7.4.0-win-x64.msi
I debugged and found out that the exception is ocurring at this location (ModuleIntrinsics.UpdatePath):
| insertIndex = path.IndexOf(Path.PathSeparator, PathContainsSubstring(path, pathToAdd)); |
The arguments for UpdatePath are:
path: a string with a ; separated list of paths
pathToAdd: another string with a ; separated list of paths
insertIndex: 0
The call that is failing is the one to path.IndexOf, which is passed ; and -1 (which is the result from the call to PathContainsSubstring).
The problem only happens because pathToAdd has several paths with the ; separator. If it was a single path without ; it would work.
The issue seems to have been introduced in commit 3710671.


Activity
giggio commentedon Nov 16, 2023
rhubarb-geek-nz I did, I hadn't.
B-Art commentedon Nov 18, 2023
There are at least 4 ways to install Pwsh on Windows:
From MSStore, via MSI, via Winget and Unzipping the download.
Which one did you use Giovanni Bassi (@giggio) ?
https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.4
giggio commentedon Nov 18, 2023
First I tried via winget. Then via the MSI download. Same result.
giggio commentedon Nov 22, 2023
I have.
I have now also tried installing the Microsoft Store Version, and I get the same error:

giggio commentedon Nov 22, 2023
Tried now using the global tool, it also does not work:
I installed
7.3.10, as it still works. :(giggio commentedon Jan 25, 2024
The problem persists at version
7.4.1, released more recently.giggio commentedon Jan 25, 2024
Also, tried using version 7.5 preview from the store, also broken.
giggio commentedon Mar 13, 2024
I have tracked the error and added the explanation of why it is happening to the additional context section of the issue.
[-]Error starting PowerShell 7.4.0[/-][+]Error starting PowerShell 7.4.0+[/+]Fix PSModule path with multiple paths
Alvaka-KThor commentedon Apr 4, 2024
I am also experiencing this issue. I've had to use PSModulePath environment variable within System Properties in the meantime, which is not a perfect workaround.
Don't setup posh config json
w-boyd commentedon May 27, 2024
On Linux:
On Windows:
Azure DevOps pipeline yaml to reproduce the issue:
2 remaining items
hoffmanntravis commentedon Nov 6, 2024
I have reproduced this issue on Powershell 7.4.6 locally. This works:
This does not:
File Path:
C:\Users<user>\Documents\PowerShell\powershell.config.json
This seems like a clear case of regression. Please investigate and fix.
hoffmanntravis commentedon Nov 6, 2024
Couple more notes. This is still broken in Powershell Preview 7.5:
Also, note that in the example I listed in my last comment, the semicolon delimiter by itself alone is enough to break the startup of powershell.
According to this document,
;should be the delimiting character:https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath?view=powershell-7.4#modifying-psmodulepath
Editing the config file is described here:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_config?view=powershell-7.4#psmodulepath
jborean93 commentedon Nov 12, 2024
Opened #24568 to fix this problem.
hoffmanntravis commentedon Nov 13, 2024
Jordan Borean (@jborean93) First, I just wanted to say thanks for putting a PR together and getting this some attention after a long time idle.
TLDR: The underlying thesis of my comments below are we are an impacted customer of fairly advanced users that are feeling a lot of pain from this, so maybe that tips the scales towards merging. I read through the PR and noticed your comment below.
_"Waiting on an answer from the WG also takes way too much time and if I'm being honest I doubt this one will actually get merged anytime soon which is a pity.
Maybe I'll just bite the bullet and do it because I really dislike the current behavior and how it works."_
In response to that, I want to put out that we are a medium size azure customer that is fairly heavily impacted by this. We use Azure DevOps with Azure. We built our YAML deploy pipelines and our internal libraries around the notion of PSModulePath being overridable and extensible by deployment agents and users. When we use AzurePowershell@5, it actually overrides any previously set environment variables (at least with respect to PSModulePath) unless we set one on the task in YAML directly. I also tried setting it via the registry (no permission on managed agents), via a #vso var, via user env var, and via system env vars. No luck. This is burdensome compared to how it worked previously.
Prior to the issue, we ran one task template with no parameters per job that writes the modules to disk, we update the machine environment variable, and we are done. Developers can consume our libraries and templates with little to no knowledge of our tools.
Without this fix, it becomes very difficult to manage those modules and how we have it set up. Yes, we can likely do an install-module or something, but checking out a repository, writing to disk, and setting the environment variable works great for us. And then it broke so we've been stuck on 7.2 for months. Recently I ended up writing my own randomizer and testing with NIST tools instead of using PS 7.4 Get-SecureRandom, which would have been so much more convenient.
Not sure if that tips the scales or not in favor of merging but I hope it does 🙂. And maybe provides a little cover if there are issues. You can definitely blame me, because we're really feeling pain with out it, so there's one reason to do it anyway haha. We really dislike the behavior right now ourselves, because it doesn't work for us at all and broke our existing process.
Thanks so much for your help!
Travis
ChrisTX commentedon Oct 28, 2026
This is fixed on master by #26565 (in 7.7.0-preview.1 and later), which also fixed the duplicate #26536. Could this issue be closed, and could a fix be considered for 7.6, since that's the current LTS release? v7.6.9 still crashes at startup, or in
ForEach-Object -Parallelrunspaces, when$env:PSModulePathis already set (e.g. when startingpwshfrompwsh) and apowershell.config.jsonsetsPSModulePathto multiple paths.#26565 is a fairly large refactor, which needed test fixes afterwards (#27343, #27344), so it may not suit a servicing release. A smaller fix that only touches the two places that break is:
UpdatePath:PathContainsSubstring(path, pathToAdd)returns -1 for a combinedpathToAdd, sopath.IndexOf(Path.PathSeparator, -1)throws. Look up the last entry ofpathToAddinstead.AddToPath: advanceinsertPositionafter each inserted entry, so a combined path keeps its order, and compare it againstresult.Lengthinstead ofbasePath.Length.We've shipped this in the Arch Linux (AUR) package of 7.6.9, and the full Pester and xUnit suites pass with it. I'm happy to open a PR against the 7.6 release branch if you'd take it there.
upgpkg: powershell 7.6.9-2
kilasuit commentedon Nov 3, 2026
Christian Pfeiffer (@ChrisTX) it's probs best if you don't mind raising a new issue asking for the backport of #26565 & other required test fixes that were needed or you can make your suggestion about a possible smaller fix instead & the team can decide which option they decide on taking to the 7.6.x release branch.
Whilst in the meantime we can close this issue out as it now having been fixed. Sound good to you?
ChrisTX commentedon Nov 3, 2026
Ryan Yates (@kilasuit) Can do if that's better. For reference, I'm using this minimal patch in my build for ArchLinux AUR. If you think that's better, I can open a PR for that? It's really just this fix, and would thus work in a minimal fashion on the 7.6 branch?
kilasuit commentedon Nov 3, 2026
The final decision on whether it make senses to diverge with a new fix or it makes it easier just to backport what's already been merged, is a maintainer team decision to make.
Which is easier & quicker decided with a short issue that's to the point.
ChrisTX commentedon Nov 3, 2026
Ryan Yates (@kilasuit) Opened #28306 for the 7.6 fix, with both options. Fine to close this one.