Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
sshree43
Posts: 33 Joined: Wed Jun 27, 2018 11:57 am
Post
by sshree43 » Tue Jul 03, 2018 10:05 am
Hi Expert,
I am trying to move the file to archive except for 2 files and just want to copy this files to archive..
but getting the error message input parameter is invalid
Code: Select all
$sourcedir = 'C:\Users\garang\Documents\input_files\Advisory_rate'
$destdir = 'C:\Users\garang\Documents\input_files\Advisory_rate\Archive'
Get-ChildItem -File -Path $sourcedir |
Move-Item $sourcedir $destdir[b] -Exclude "ven late sapping.xlsx","Qk PU waisting.xlsx"[/b]
files are
ven late sapping.xlsx
Qk PU waisting.xlsx
ven late sapping_1.xlsx
Qk PU waisting_1.xlsx
thanks
jvierra
Posts: 14672 Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:
Post
by jvierra » Tue Jul 03, 2018 10:15 am
Try it like this:
Code: Select all
$sourcedir = 'C:\Users\garang\Documents\input_files\Advisory_rate\*'
$destdir = 'C:\Users\garang\Documents\input_files\Advisory_rate\Archive'
Get-ChildItem -File -Path $sourcedir -Exclude 'ven late sapping.xlsx','Qk PU waisting.xlsx'|
Move-Item =Destination $destdir
sshree43
Posts: 33 Joined: Wed Jun 27, 2018 11:57 am
Post
by sshree43 » Tue Jul 03, 2018 10:45 am
sorry not working and not moving any file
jvierra
Posts: 14672 Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:
Post
by jvierra » Tue Jul 03, 2018 10:48 am
Sorry. I forgot the parameter name:
Code: Select all
$sourcedir = 'C:\Users\garang\Documents\input_files\Advisory_rate\*'
$destdir = 'C:\Users\garang\Documents\input_files\Advisory_rate\Archive'
Get-ChildItem -File -Path $sourcedir -Exclude 'ven late sapping.xlsx','Qk PU waisting.xlsx'|
Move-Item =Destination $destdir
sshree43
Posts: 33 Joined: Wed Jun 27, 2018 11:57 am
Post
by sshree43 » Tue Jul 03, 2018 10:54 am
no still not moving
jvierra
Posts: 14672 Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:
Post
by jvierra » Tue Jul 03, 2018 11:03 am
Perhaps your selection criteria is wrong. Do you get an output from the selection part?
]b]$sourcedir = 'C:\Users\garang\Documents\input_files\Advisory_rate\*'
$destdir = 'C:\Users\garang\Documents\input_files\Advisory_rate\Archive'
Get-ChildItem -File -Path $sourcedir -Exclude 'ven late sapping.xlsx','Qk PU waisting.xlsx'[/b]
sshree43
Posts: 33 Joined: Wed Jun 27, 2018 11:57 am
Post
by sshree43 » Tue Jul 03, 2018 11:17 am
i removed this from the source directory due to giving an error with your first solution
It's working now moving all files the except two files..How to copy that two files to destination directory in the same statement
I tried with pipe to your statement but not working
Code: Select all
$sourcedir = 'C:\Users\garang\Documents\input_files\Advisory_rate\*'
$destdir = 'C:\Users\garang\Documents\input_files\Advisory_rate\Archive'
Get-ChildItem -File -Path $sourcedir -Exclude 'ven late sapping.xlsx','Qk PU waisting.xlsx'|
Move-Item =Destination $destdir |
Copy-Item $sourcedir -Destination $destdir -Recurse
jvierra
Posts: 14672 Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:
Post
by jvierra » Tue Jul 03, 2018 11:25 am
You can't. It requires a completely different coding approach. Just write two statements.
sshree43
Posts: 33 Joined: Wed Jun 27, 2018 11:57 am
Post
by sshree43 » Tue Jul 03, 2018 11:34 am
How can i give helpful and correct solution remarks
jvierra
Posts: 14672 Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:
Post
by jvierra » Tue Jul 03, 2018 11:41 am
sshree43 wrote: ↑ Tue Jul 03, 2018 11:34 am
How can i give helpful and correct solution remarks
I don't understand this question.