`Remove-Item -WhatIf` on Junctions and SymbolicLinks (ReparsePoints) doesn't honor `-WhatIf`, removes the item anyway.
Prerequisites
- [X] Write a descriptive title.
- [X] Make sure you are able to repro it on the latest released version
- [X] Search the existing issues.
- [X] Refer to the FAQ.
- [X] Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
While testing deleting symbolic links with Remove-Item in Windows PowerShell I ran in to issues and switched to PowerShell 7.3.4, where the command ran as expected, until I realized it deleted the files even though I had used the -WhatIf parameter.
Specifically I was deleting a symbolic link, but I also tested it on a junction point.
The actual command:
Remove-Item "$_\Documents" -force -whatif
$_ contained the directory info object of a user's folder on a file store. I was using the local file store at the time, so a local hard drive, not UNC paths.
I believe Windows PowerShell has the same issue, as it was providing an error regarding deleting the symbolic link after printing the verbose 'whatif:' response, due to some mismatch of tag information.
Expected behavior
Expected the file/folder to not be deleted.
Actual behavior
Folder was deleted even though the verbose output indicated 'whatif:'
What if: Performing the operation "Remove Directory" on target "E:\Shares\Users Folders\RNE_LdrFF\Documents".
Error details
No response
Environment data
Name Value
---- -----
PSVersion 7.3.4
PSEdition Core
GitCommitId 7.3.4
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
This does appear to be specific to links and force appears to be a red herring. (It is LESS forceful in Remove-Item than some other things)
First line creates a link,
Second shows it is there
Third runs del with -whatif (no -force) What if message appears
Fourth shows the item has gone.
It meets my definition of a bug. I'm not sure if it is the cmdlet or the provider at fault, so I'm not going to change the tags for now.
@msftrncs Can you check that the simpler repro I've shown is valid, and possibly update the title ?
@jhoneill, you appear to be correct, the -force is not required in PowerShell 7 at all, the symbolic link is deleted even though -WhatIf was specified, and it only appears to happen for ReparsePoint items.
Will update title accordingly.
@msftrncs Thanks for that. I'll try to get some attention for this.
It didn't make it onto the agenda for this week's cmdlet working group meeting but I'll try to get it onto a future one
I have marked this as a bug. It's unclear if the bug is in the the Remove-Item cmdlet or the File System provider - my hunch is the cmdlet because that's where whatif should be handled, but it might be a result of something the provider does.
This issue has been marked as duplicate and has not had any activity for 1 day. It has been closed for housekeeping purposes.