Move-Item -exclude throwing redundant error
up vote
2
down vote
favorite
I'm moving a group of files from a directory and I'm using the -exclude
modifier to exclude files with a .gpg extension:
Move-Item -path $encrypted_folder*.* -EXCLUDE *.gpg -destination $final_dir
And while this works fine by moving every non-.gpg file, I get the following error every time Move-Item
encounters a .gpg file:
Move-Item : Cannot move item because the item at 'C:UsersThisUserDocumentsPGP Encryption testUUIDxxxx.gpg' does not exist.
At C:UsersThisUserDocumentsPGP Encryption testyyyy.ps1:41 char:1
+ Move-Item -path $encrypted_folder*.* -EXCLUDE *.gpg -destination $final_dir
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand
Why is it complaining that it can't move a .gpg item because it doesn't exist, when I've set the command to exclude .gpg items? (which definitely exist). The exclusion is occurring, and a subsequent command to -include
.gpg files works fine, but I'm not happy with the errors on my -exclude
command.
powershell
add a comment |
up vote
2
down vote
favorite
I'm moving a group of files from a directory and I'm using the -exclude
modifier to exclude files with a .gpg extension:
Move-Item -path $encrypted_folder*.* -EXCLUDE *.gpg -destination $final_dir
And while this works fine by moving every non-.gpg file, I get the following error every time Move-Item
encounters a .gpg file:
Move-Item : Cannot move item because the item at 'C:UsersThisUserDocumentsPGP Encryption testUUIDxxxx.gpg' does not exist.
At C:UsersThisUserDocumentsPGP Encryption testyyyy.ps1:41 char:1
+ Move-Item -path $encrypted_folder*.* -EXCLUDE *.gpg -destination $final_dir
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand
Why is it complaining that it can't move a .gpg item because it doesn't exist, when I've set the command to exclude .gpg items? (which definitely exist). The exclusion is occurring, and a subsequent command to -include
.gpg files works fine, but I'm not happy with the errors on my -exclude
command.
powershell
What happens is you put single quotes around your -Exclude items (-Exclude '.gpg')...or create a variable called $exclude='.gpg' then set your exclude parameter to: -Exclude $exclude
– DukeSilversJazz
Aug 17 '17 at 14:36
@RMarkwald The error occurs whether I use an $exclude variable, single quotes or no quotes. I'm just finding it bizarre that it's doing what I want it to do, yet throwing those errors as a by-product.
– duney
Aug 17 '17 at 14:46
which ps version? It looks like this is(was) a known bug: github.com/PowerShell/PowerShell/issues/2385
– wmz
Aug 17 '17 at 15:19
What about: Get-ChildItem -Path $encrypted_folder -Exclude $exclude -Recurse | Move-Item -Destination $final_dir...of course I set $exclude='*.gpg'...you may or may not need -Recurse, I guess depends on if there's other folders etc you want it to also go through.
– DukeSilversJazz
Aug 17 '17 at 15:34
@wmz Good find - My PSVersion is 3.0; BuildVersion is 6.2.9200.22198. The bug must have been around for a while as the version in the github post you mention is 6.0.0-alpha. I'll see if I can update, which is always a struggle on these corporate networks..
– duney
Aug 17 '17 at 16:00
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm moving a group of files from a directory and I'm using the -exclude
modifier to exclude files with a .gpg extension:
Move-Item -path $encrypted_folder*.* -EXCLUDE *.gpg -destination $final_dir
And while this works fine by moving every non-.gpg file, I get the following error every time Move-Item
encounters a .gpg file:
Move-Item : Cannot move item because the item at 'C:UsersThisUserDocumentsPGP Encryption testUUIDxxxx.gpg' does not exist.
At C:UsersThisUserDocumentsPGP Encryption testyyyy.ps1:41 char:1
+ Move-Item -path $encrypted_folder*.* -EXCLUDE *.gpg -destination $final_dir
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand
Why is it complaining that it can't move a .gpg item because it doesn't exist, when I've set the command to exclude .gpg items? (which definitely exist). The exclusion is occurring, and a subsequent command to -include
.gpg files works fine, but I'm not happy with the errors on my -exclude
command.
powershell
I'm moving a group of files from a directory and I'm using the -exclude
modifier to exclude files with a .gpg extension:
Move-Item -path $encrypted_folder*.* -EXCLUDE *.gpg -destination $final_dir
And while this works fine by moving every non-.gpg file, I get the following error every time Move-Item
encounters a .gpg file:
Move-Item : Cannot move item because the item at 'C:UsersThisUserDocumentsPGP Encryption testUUIDxxxx.gpg' does not exist.
At C:UsersThisUserDocumentsPGP Encryption testyyyy.ps1:41 char:1
+ Move-Item -path $encrypted_folder*.* -EXCLUDE *.gpg -destination $final_dir
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand
Why is it complaining that it can't move a .gpg item because it doesn't exist, when I've set the command to exclude .gpg items? (which definitely exist). The exclusion is occurring, and a subsequent command to -include
.gpg files works fine, but I'm not happy with the errors on my -exclude
command.
powershell
powershell
asked Aug 17 '17 at 14:10
duney
112
112
What happens is you put single quotes around your -Exclude items (-Exclude '.gpg')...or create a variable called $exclude='.gpg' then set your exclude parameter to: -Exclude $exclude
– DukeSilversJazz
Aug 17 '17 at 14:36
@RMarkwald The error occurs whether I use an $exclude variable, single quotes or no quotes. I'm just finding it bizarre that it's doing what I want it to do, yet throwing those errors as a by-product.
– duney
Aug 17 '17 at 14:46
which ps version? It looks like this is(was) a known bug: github.com/PowerShell/PowerShell/issues/2385
– wmz
Aug 17 '17 at 15:19
What about: Get-ChildItem -Path $encrypted_folder -Exclude $exclude -Recurse | Move-Item -Destination $final_dir...of course I set $exclude='*.gpg'...you may or may not need -Recurse, I guess depends on if there's other folders etc you want it to also go through.
– DukeSilversJazz
Aug 17 '17 at 15:34
@wmz Good find - My PSVersion is 3.0; BuildVersion is 6.2.9200.22198. The bug must have been around for a while as the version in the github post you mention is 6.0.0-alpha. I'll see if I can update, which is always a struggle on these corporate networks..
– duney
Aug 17 '17 at 16:00
add a comment |
What happens is you put single quotes around your -Exclude items (-Exclude '.gpg')...or create a variable called $exclude='.gpg' then set your exclude parameter to: -Exclude $exclude
– DukeSilversJazz
Aug 17 '17 at 14:36
@RMarkwald The error occurs whether I use an $exclude variable, single quotes or no quotes. I'm just finding it bizarre that it's doing what I want it to do, yet throwing those errors as a by-product.
– duney
Aug 17 '17 at 14:46
which ps version? It looks like this is(was) a known bug: github.com/PowerShell/PowerShell/issues/2385
– wmz
Aug 17 '17 at 15:19
What about: Get-ChildItem -Path $encrypted_folder -Exclude $exclude -Recurse | Move-Item -Destination $final_dir...of course I set $exclude='*.gpg'...you may or may not need -Recurse, I guess depends on if there's other folders etc you want it to also go through.
– DukeSilversJazz
Aug 17 '17 at 15:34
@wmz Good find - My PSVersion is 3.0; BuildVersion is 6.2.9200.22198. The bug must have been around for a while as the version in the github post you mention is 6.0.0-alpha. I'll see if I can update, which is always a struggle on these corporate networks..
– duney
Aug 17 '17 at 16:00
What happens is you put single quotes around your -Exclude items (-Exclude '.gpg')...or create a variable called $exclude='.gpg' then set your exclude parameter to: -Exclude $exclude
– DukeSilversJazz
Aug 17 '17 at 14:36
What happens is you put single quotes around your -Exclude items (-Exclude '.gpg')...or create a variable called $exclude='.gpg' then set your exclude parameter to: -Exclude $exclude
– DukeSilversJazz
Aug 17 '17 at 14:36
@RMarkwald The error occurs whether I use an $exclude variable, single quotes or no quotes. I'm just finding it bizarre that it's doing what I want it to do, yet throwing those errors as a by-product.
– duney
Aug 17 '17 at 14:46
@RMarkwald The error occurs whether I use an $exclude variable, single quotes or no quotes. I'm just finding it bizarre that it's doing what I want it to do, yet throwing those errors as a by-product.
– duney
Aug 17 '17 at 14:46
which ps version? It looks like this is(was) a known bug: github.com/PowerShell/PowerShell/issues/2385
– wmz
Aug 17 '17 at 15:19
which ps version? It looks like this is(was) a known bug: github.com/PowerShell/PowerShell/issues/2385
– wmz
Aug 17 '17 at 15:19
What about: Get-ChildItem -Path $encrypted_folder -Exclude $exclude -Recurse | Move-Item -Destination $final_dir...of course I set $exclude='*.gpg'...you may or may not need -Recurse, I guess depends on if there's other folders etc you want it to also go through.
– DukeSilversJazz
Aug 17 '17 at 15:34
What about: Get-ChildItem -Path $encrypted_folder -Exclude $exclude -Recurse | Move-Item -Destination $final_dir...of course I set $exclude='*.gpg'...you may or may not need -Recurse, I guess depends on if there's other folders etc you want it to also go through.
– DukeSilversJazz
Aug 17 '17 at 15:34
@wmz Good find - My PSVersion is 3.0; BuildVersion is 6.2.9200.22198. The bug must have been around for a while as the version in the github post you mention is 6.0.0-alpha. I'll see if I can update, which is always a struggle on these corporate networks..
– duney
Aug 17 '17 at 16:00
@wmz Good find - My PSVersion is 3.0; BuildVersion is 6.2.9200.22198. The bug must have been around for a while as the version in the github post you mention is 6.0.0-alpha. I'll see if I can update, which is always a struggle on these corporate networks..
– duney
Aug 17 '17 at 16:00
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
I would rewrite the expression as follows:
gci $encrypted_folder*.* -exclude *.gpg | move-item -destination $final_dir
You may also build more sophisticated filters using where-object
and -match/notmatch
, for example exclude only those with 4 or more chars before extension:
gci |? name -notmatch '^.{4,}.gpg$' | [rest of processing here]
Explanation
As noted in comments, this error is reported here: https://github.com/PowerShell/PowerShell/issues/2385. I can replicate it in PS 4 as well:
$psversiontable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.18728
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
New-Item -Name "foo.txt" -ItemType File
New-Item -Name "bar.txt" -ItemType File
Move-Item -Path ".*" -Destination "move.txt" -Exclude "bar*"
Move-Item : Cannot move item because the item at 'C:temptestbar.txt' does not exist.
At line:1 char:1
+ Move-Item -Path ".*" -Destination "move.txt" -Exclude "bar*"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand
The fix for this is in the not-yet-released version 6 (https://github.com/PowerShell/PowerShell/tree/v6.0.0-beta.5).
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
I would rewrite the expression as follows:
gci $encrypted_folder*.* -exclude *.gpg | move-item -destination $final_dir
You may also build more sophisticated filters using where-object
and -match/notmatch
, for example exclude only those with 4 or more chars before extension:
gci |? name -notmatch '^.{4,}.gpg$' | [rest of processing here]
Explanation
As noted in comments, this error is reported here: https://github.com/PowerShell/PowerShell/issues/2385. I can replicate it in PS 4 as well:
$psversiontable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.18728
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
New-Item -Name "foo.txt" -ItemType File
New-Item -Name "bar.txt" -ItemType File
Move-Item -Path ".*" -Destination "move.txt" -Exclude "bar*"
Move-Item : Cannot move item because the item at 'C:temptestbar.txt' does not exist.
At line:1 char:1
+ Move-Item -Path ".*" -Destination "move.txt" -Exclude "bar*"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand
The fix for this is in the not-yet-released version 6 (https://github.com/PowerShell/PowerShell/tree/v6.0.0-beta.5).
add a comment |
up vote
2
down vote
I would rewrite the expression as follows:
gci $encrypted_folder*.* -exclude *.gpg | move-item -destination $final_dir
You may also build more sophisticated filters using where-object
and -match/notmatch
, for example exclude only those with 4 or more chars before extension:
gci |? name -notmatch '^.{4,}.gpg$' | [rest of processing here]
Explanation
As noted in comments, this error is reported here: https://github.com/PowerShell/PowerShell/issues/2385. I can replicate it in PS 4 as well:
$psversiontable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.18728
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
New-Item -Name "foo.txt" -ItemType File
New-Item -Name "bar.txt" -ItemType File
Move-Item -Path ".*" -Destination "move.txt" -Exclude "bar*"
Move-Item : Cannot move item because the item at 'C:temptestbar.txt' does not exist.
At line:1 char:1
+ Move-Item -Path ".*" -Destination "move.txt" -Exclude "bar*"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand
The fix for this is in the not-yet-released version 6 (https://github.com/PowerShell/PowerShell/tree/v6.0.0-beta.5).
add a comment |
up vote
2
down vote
up vote
2
down vote
I would rewrite the expression as follows:
gci $encrypted_folder*.* -exclude *.gpg | move-item -destination $final_dir
You may also build more sophisticated filters using where-object
and -match/notmatch
, for example exclude only those with 4 or more chars before extension:
gci |? name -notmatch '^.{4,}.gpg$' | [rest of processing here]
Explanation
As noted in comments, this error is reported here: https://github.com/PowerShell/PowerShell/issues/2385. I can replicate it in PS 4 as well:
$psversiontable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.18728
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
New-Item -Name "foo.txt" -ItemType File
New-Item -Name "bar.txt" -ItemType File
Move-Item -Path ".*" -Destination "move.txt" -Exclude "bar*"
Move-Item : Cannot move item because the item at 'C:temptestbar.txt' does not exist.
At line:1 char:1
+ Move-Item -Path ".*" -Destination "move.txt" -Exclude "bar*"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand
The fix for this is in the not-yet-released version 6 (https://github.com/PowerShell/PowerShell/tree/v6.0.0-beta.5).
I would rewrite the expression as follows:
gci $encrypted_folder*.* -exclude *.gpg | move-item -destination $final_dir
You may also build more sophisticated filters using where-object
and -match/notmatch
, for example exclude only those with 4 or more chars before extension:
gci |? name -notmatch '^.{4,}.gpg$' | [rest of processing here]
Explanation
As noted in comments, this error is reported here: https://github.com/PowerShell/PowerShell/issues/2385. I can replicate it in PS 4 as well:
$psversiontable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.18728
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
New-Item -Name "foo.txt" -ItemType File
New-Item -Name "bar.txt" -ItemType File
Move-Item -Path ".*" -Destination "move.txt" -Exclude "bar*"
Move-Item : Cannot move item because the item at 'C:temptestbar.txt' does not exist.
At line:1 char:1
+ Move-Item -Path ".*" -Destination "move.txt" -Exclude "bar*"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Move-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.MoveItemCommand
The fix for this is in the not-yet-released version 6 (https://github.com/PowerShell/PowerShell/tree/v6.0.0-beta.5).
edited Nov 28 at 21:53
Run5k
10.6k72749
10.6k72749
answered Aug 17 '17 at 19:05
wmz
5,63211127
5,63211127
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1241850%2fmove-item-exclude-throwing-redundant-error%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What happens is you put single quotes around your -Exclude items (-Exclude '.gpg')...or create a variable called $exclude='.gpg' then set your exclude parameter to: -Exclude $exclude
– DukeSilversJazz
Aug 17 '17 at 14:36
@RMarkwald The error occurs whether I use an $exclude variable, single quotes or no quotes. I'm just finding it bizarre that it's doing what I want it to do, yet throwing those errors as a by-product.
– duney
Aug 17 '17 at 14:46
which ps version? It looks like this is(was) a known bug: github.com/PowerShell/PowerShell/issues/2385
– wmz
Aug 17 '17 at 15:19
What about: Get-ChildItem -Path $encrypted_folder -Exclude $exclude -Recurse | Move-Item -Destination $final_dir...of course I set $exclude='*.gpg'...you may or may not need -Recurse, I guess depends on if there's other folders etc you want it to also go through.
– DukeSilversJazz
Aug 17 '17 at 15:34
@wmz Good find - My PSVersion is 3.0; BuildVersion is 6.2.9200.22198. The bug must have been around for a while as the version in the github post you mention is 6.0.0-alpha. I'll see if I can update, which is always a struggle on these corporate networks..
– duney
Aug 17 '17 at 16:00