Title: New-Item -Force does not have expected behavior for all types · Issue #17656 · PowerShell/PowerShell · GitHub
Open Graph Title: New-Item -Force does not have expected behavior for all types · Issue #17656 · PowerShell/PowerShell
X Title: New-Item -Force does not have expected behavior for all types · Issue #17656 · 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/17656
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"New-Item -Force does not have expected behavior for all types","articleBody":"### Prerequisites\r\n\r\n- [X] Write a descriptive title.\r\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\r\n- [X] Search the existing issues.\r\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- [x] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://docs.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\r\n\r\n### Steps to reproduce\r\n\r\nIssue is `-Force` does not seem to understand junctions. It thinks they are directories and fails to remove them because they are not empty.\r\n\r\nWorks fine with file types. (see screenshot)\r\n\r\nMost types including registry entries allow `-Force` to overwrite the item. Logically `-Force` should do the same for a Junction.\r\n\r\nDue to `-Force` not working you must first `Remove-Item` prior to `New-Item`, which works perfectly fine. `Remove-Item` simply removes the junction and does not complain that it is not empty. `New-Item -Force` needs the same intelligence.\r\n\r\n\r\n### Expected behavior\r\n\r\n```console\r\nPS\u003e New-Item MyWindows -Type Junction -Value C:\\Windows\\\r\nPS\u003e New-Item MyWindows -Type Junction -Value C:\\Windows\\ -Force\r\nPS\u003e\r\n```\r\n\r\n\r\n### Actual behavior\r\n\r\n```console\r\nPS\u003e New-Item MyWindows -Type Junction -Value C:\\Windows\\\r\nPS\u003e New-Item MyWindows -Type Junction -Value C:\\Windows\\ -Force\r\nNew-Item: Directory C:\\Temp\\MyWindows cannot be removed because it is not empty.\r\nPS\u003e\r\n```\r\n\r\n\r\n### Error details\r\n\r\n```console\r\nException :\r\n Type : System.IO.IOException\r\n Message : Directory C:\\Temp\\MyWindows cannot be removed because it is not empty.\r\n HResult : -2146232800\r\nTargetObject : C:\\Temp\\MyWindows\r\nCategoryInfo : WriteError: (C:\\Temp\\MyWindows:String) [New-Item], IOException\r\nFullyQualifiedErrorId : DirectoryNotEmpty,Microsoft.PowerShell.Commands.NewItemCommand\r\nInvocationInfo :\r\n MyCommand : New-Item\r\n ScriptLineNumber : 1\r\n OffsetInLine : 1\r\n HistoryId : 5\r\n Line : New-Item MyWindows -Type Junction -Value C:\\Windows\\ -Force\r\n PositionMessage : At line:1 char:1\r\n + New-Item MyWindows -Type Junction -Value C:\\Windows\\ -Force\r\n + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n InvocationName : New-Item\r\n CommandOrigin : Internal\r\nScriptStackTrace : at \u003cScriptBlock\u003e, \u003cNo file\u003e: line 1\r\nPipelineIterationInfo :\r\n```\r\n\r\n\r\n### Environment data\r\n\r\n```powershell\r\nName Value\r\n---- -----\r\nPSVersion 7.2.5\r\nPSEdition Core\r\nGitCommitId 7.2.5\r\nOS Microsoft Windows 10.0.19044\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n\r\n\r\n### Visuals\r\n\r\n\r\n","author":{"url":"https://github.com/tolgabalci","@type":"Person","name":"tolgabalci"},"datePublished":"2022-07-09T16:54:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/17656/PowerShell/issues/17656"}
| 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:79130fd9-5785-1293-dafe-9f4995580e36 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8728:21DF5A:16B1217:1EB2F1E:6A5463C0 |
| html-safe-nonce | 12844e25a684218aae806afaf061d2c7c42b8968f285a547da30f418a4359041 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzI4OjIxREY1QToxNkIxMjE3OjFFQjJGMUU6NkE1NDYzQzAiLCJ2aXNpdG9yX2lkIjoiMjUzNzYxODc4MTEwNzkwNTkyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7da16921c34a81019b795e87b571f6538004b3ee2b3dcedadb87429f4a4af2c9 |
| hovercard-subject-tag | issue:1299722811 |
| 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/17656/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7d936f8f5be5e37576512364527fda0b8146904fb437f2530a3306cd0e6d2989/PowerShell/PowerShell/issues/17656 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7d936f8f5be5e37576512364527fda0b8146904fb437f2530a3306cd0e6d2989/PowerShell/PowerShell/issues/17656 |
| 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 | tolgabalci |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 6d28624802c2f7d9500239dd6870ed7031b7353b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width