I have a folder containing files, folders, and a target subfolder. I'm trying to move all contents of the folder into the target subfolder (excluding the target subfolder) using Move-Item. When I do so I get an unexpected "does not exist" error for the target subfolder. Am I misusing the command? Is there another argument that achieves what I want?
PS C:\test> dir
Directory: C:\test
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 6/14/2023 1:06 PM anotherFolder
d----- 6/14/2023 12:50 PM subfolder
-a---- 6/14/2023 12:50 PM 6 ItemA
-a---- 6/14/2023 12:50 PM 6 ItemB
-a---- 6/14/2023 12:50 PM 6 ItemC
PS C:\test> Move-Item * -Destination subfolder -Exclude subfolder
Move-Item : Cannot move item because the item at 'C:\test\subfolder' does not exist.
At line:1 char:1
+ Move-Item * -Destination subfolder -Exclude subfolder
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand
PS C:\test> dir
Directory: C:\test
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 6/14/2023 12:50 PM subfolder
Looks like the move succeeded but I would prefer to not get an error for simple move operation... if I try without the Exclude argument, I get a different error:
PS C:\test> Move-Item * -Destination subfolder
Move-Item : The parameter is incorrect.
At line:1 char:1
+ Move-Item * -Destination subfolder
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (C:\test\subfolder:DirectoryInfo) [Move-Item], IOException
+ FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand
PS C:\test>