Software⏱️ 3 min read📅 2026-06-11

How to Fix: Move-Item -exclude throwing redundant error

Move-Item command error when excluding .gpg files.

Quick Answer: Use the -Recurse parameter to move all files in the directory, including subdirectories.

The error message 'Cannot move item because the item at ... does not exist' is thrown by the Move-Item cmdlet when it encounters a file with a .gpg extension that has been excluded from the move operation. This occurs even though the exclusion modifier (-exclude) is specified to exclude files with the .gpg extension.

This error can be frustrating for users who are trying to move groups of files and have explicitly excluded certain types of files. However, it's essential to understand why this error happens and how to resolve it.

🔍 Why This Happens

  • The primary reason for this error is that the -exclude modifier only works when used in conjunction with the -Recurse parameter. When the -Recurse parameter is not specified, the cmdlet will still attempt to move files that have been excluded from the move operation, resulting in the 'Does not exist' error message.
  • Another possible reason for this error is that the file system may be experiencing issues or there might be permissions problems that prevent the Move-Item cmdlet from accessing certain files.

✅ Best Solutions to Fix It

Using the -Recurse parameter with the -Exclude parameter

  1. Step 1: Add the -Recurse parameter to the Move-Item cmdlet to ensure that all subdirectories are included in the move operation. This will prevent the cmdlet from attempting to move files that have been excluded.
  2. Step 2: Modify the Move-Item cmdlet as follows: Move-Item -path $encrypted_folder ecurse: ecurse:*.* -EXCLUDE *.gpg -destination $final_dir
  3. Step 3: This change ensures that all subdirectories and files within them are included in the move operation, while still excluding files with the .gpg extension.

Using a separate cmdlet to exclude specific files

  1. Step 1: Instead of using the -exclude parameter, use a separate cmdlet (such as Get-ChildItem or Remove-Item) to exclude files with the .gpg extension before moving them.
  2. Step 2: Use the following command: Get-ChildItem -Path $encrypted_folder -Filter *.gpg | Remove-Item -Force

💡 Conclusion

To resolve the 'Cannot move item because the item at ... does not exist' error message, use either of the two primary fix methods outlined above. By adding the -Recurse parameter to the Move-Item cmdlet or using a separate cmdlet to exclude specific files, you can ensure that only files with the .gpg extension are excluded from the move operation.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions