Title: Set-Location fails for paths with special characters when switching drives · Issue #25282 · PowerShell/PowerShell · GitHub
Open Graph Title: Set-Location fails for paths with special characters when switching drives · Issue #25282 · PowerShell/PowerShell
X Title: Set-Location fails for paths with special characters when switching drives · Issue #25282 · PowerShell/PowerShell
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 reprodu...
Open Graph 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 PowerSh...
X 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 PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/25282
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Set-Location fails for paths with special characters when switching drives","articleBody":"### Prerequisites\n\n- [x] Write a descriptive title.\n- [x] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\n- [x] Search the existing issues.\n- [x] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\n- [x] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\n\n### Steps to reproduce\n\n### Steps to Reproduce \nUse two different, valid and accessible drive letters on your system, I use C: and E:\n\n1. Create a directory with special characters in its name:\n ```powershell\n md \"e:\\This my test [Folder] with bracket characters\"\n ```\n2. Navigate into the directory:\n ```powershell\n cd 'e:\\This my test `[Folder`] with bracket characters\\'\n ```\n3. Switch to another drive:\n ```powershell\n c:\n ```\n4. Attempt to switch back to the original directory:\n ```powershell\n e: \n ```\n **Observed Result:** Error: \n ```\n Set-Location: Cannot find path 'E:\\This my test [Folder] with bracket characters' because it does not exist.\n ```\n5. Use `-LiteralPath` when switching back to the original directory:\n ```powershell\n cd -LiteralPath e:\n ```\n **Observed Result:** \n Successful navigation to the directory:\n ```\n PS E:\\This my test [Folder] with bracket characters\u003e\n ```\n\n\n### Expected behavior\n\n```console\nPS C:\\\u003e e:\nPS E:\\This my test [Folder] with bracket characters\u003e\n```\n\n### Actual behavior\n\n```console\nPS C:\\\u003e e:\nSet-Location: Cannot find path 'E:\\This my test [Folder] with bracket characters' because it does not exist.\nPS C:\\\u003e\n```\n\n### Error details\n\n```console\nException :\n Type : System.Management.Automation.ItemNotFoundException\n ErrorRecord :\n Exception :\n Type : System.Management.Automation.ParentContainsErrorRecordException\n Message : Cannot find path 'E:\\This my test [Folder] with bracket characters'\nbecause it does not exist.\n HResult : -2146233087\n TargetObject : E:\\This my test [Folder] with bracket characters\n CategoryInfo : ObjectNotFound: (E:\\This my test [Fo… bracket\ncharacters:String) [], ParentContainsErrorRecordException\n FullyQualifiedErrorId : PathNotFound\n ItemName : E:\\This my test [Folder] with bracket characters\n SessionStateCategory : Drive\n TargetSite :\n Name : SetLocation\n DeclaringType : [System.Management.Automation.SessionStateInternal]\n MemberType : Method\n Module : System.Management.Automation.dll\n Message : Cannot find path 'E:\\This my test [Folder] with bracket characters'\nbecause it does not exist.\n Source : System.Management.Automation\n HResult : -2146233087\n StackTrace :\n at System.Management.Automation.SessionStateInternal.SetLocation(String path,\nCmdletProviderContext context, Boolean literalPath)\n at Microsoft.PowerShell.Commands.SetLocationCommand.ProcessRecord()\nTargetObject : E:\\This my test [Folder] with bracket characters\nCategoryInfo : ObjectNotFound: (E:\\This my test [Fo… bracket characters:String)\n[Set-Location], ItemNotFoundException\nFullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand\nInvocationInfo :\n MyCommand : Set-Location\n ScriptLineNumber : 1\n OffsetInLine : 1\n HistoryId : 91\n Line : Set-Location $MyInvocation.MyCommand.Name\n Statement : Set-Location $MyInvocation.MyCommand.Name\n PositionMessage : At line:1 char:1\n + Set-Location $MyInvocation.MyCommand.Name\n + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n InvocationName : Set-Location\n CommandOrigin : Internal\nScriptStackTrace : at \u003cScriptBlock\u003e, \u003cNo file\u003e: line 1\n at \u003cScriptBlock\u003e, \u003cNo file\u003e: line 1\nPipelineIterationInfo :\n 0\n 1\n```\n\n### Environment data\n\n```powershell\nName Value\n---- -----\nPSVersion 7.5.0\nPSEdition Core\nGitCommitId 7.5.0\nOS Microsoft Windows 10.0.26100\nPlatform Win32NT\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\nPSRemotingProtocolVersion 2.3\nSerializationVersion 1.1.0.1\nWSManStackVersion 3.0\n```\n\n### Visuals\n\n_No response_","author":{"url":"https://github.com/genXdev","@type":"Person","name":"genXdev"},"datePublished":"2025-04-05T00:00:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/25282/PowerShell/issues/25282"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e1c05560-5599-df23-b3ec-bf7b2a405e78 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A922:3721E4:9DCEAB:D58D9D:6A59389B |
| html-safe-nonce | bd259be3eae6622cdf0cef6ca0ecb4b8fc039afcae2aebea05a3b6e8c9642d47 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTIyOjM3MjFFNDo5RENFQUI6RDU4RDlEOjZBNTkzODlCIiwidmlzaXRvcl9pZCI6IjM3MDA4MzkxMzczNzkxNzA0NTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8c1c9036d06d044a08d77d318426d6ea69c0acfa0ea0fba6df0f1550dbcee728 |
| hovercard-subject-tag | issue:2973572269 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/25282/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9652349d8a833798a0556b27ac67b2a9586ec75d03c9cb475dbfee8f45083597/PowerShell/PowerShell/issues/25282 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9652349d8a833798a0556b27ac67b2a9586ec75d03c9cb475dbfee8f45083597/PowerShell/PowerShell/issues/25282 |
| og:image:alt | 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 PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | genXdev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1b31c9453e1607b2781513084b4770f67217e549834c85b76960d7b13626f7c8 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 220f27779da5b92b5e17fcaef93e474cc8affba3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width