This topic contains 5 replies, has 3 voices, and was last updated by Stephen Owen 2 years, 1 month ago.
-
AuthorPosts
-
March 9, 2016 at 10:56 am #36326
I am trying to take a zip file that can be in any directory using the gci and $_. I am using a foreach to find it, move it, unzip and process the documents before working on the next zip. Still the $_ is coming back null. Any suggestions?
$FileLimit = 1
$Counter = 0gci -Path "D:\AR Lockbox Checks\*ny*\" -Filter "*.zip"| Select-Object -first $FileLimit | %{
Move-Item $_ -destination "D:\AR Lockbox Checks\"
Invoke-command -ScriptBlock {C:\Windows\System32\cscript.exe '\\bmnj62-p-obas3\D$\AR Lockbox Checks\Scripts\unzip AR Chase Lockbox.wsf'}
Start-Sleep -Seconds 30
Copy-Item -Path "D:\AR Lockbox Checks\index*" -Destination "D:\AR Lockbox Checks\OnbaseImport\ReadyIndex$date$time.txt"
Copy-Item -Path "D:\AR Lockbox Checks\index*" -Destination "D:\AR Lockbox Checks\OnbaseImport\SuppIndex$date$time.txt"
Remove-Item -Path "D:\AR Lockbox Checks\Readme*"
Remove-Item -Path "D:\AR Lockbox Checks\index*"
Move-Item -Path "D:\AR Lockbox Checks\*.zip" -Destination "D:\AR Lockbox Checks\BackupZip\" -Exclude "D:\AR Lockbox Checks\*ny*","D:\AR Lockbox Checks\*checkimg*"
Move-Item -Path "D:\AR Lockbox Checks\*.tif" -Destination "D:\AR Lockbox Checks\OnbaseImport\"
$Counter++}
-
March 9, 2016 at 10:59 am #36327
Every part of the code works except this part below. It cannot move the zip because after the foreach it no longer is in the pipe line?
gci -Path "D:\AR Lockbox Checks\*ny*\" -Filter "*.zip"| Select-Object -first $FileLimit | %{
Move-Item $_ -destination "D:\AR Lockbox Checks\"
-
March 9, 2016 at 11:55 am #36328
What do you get if you just run ...
gci -Path "D:\AR Lockbox Checks\*ny*\" -Filter "*.zip"
-
March 9, 2016 at 11:59 am #36329
Hello Bob,
It returns a list of the different Zip files in different sub folders.
Directory: D:\AR Lockbox Checks
Mode LastWriteTime Length Name
—- ————- —— —-
d—- 3/9/2016 2:56 PM 03032016070345.ny00227d.zip
d—- 3/9/2016 2:56 PM 03042016060047.ny00227f.zip
d—- 3/9/2016 2:56 PM 03042016070250.ny00227d.zip
d—- 3/9/2016 2:56 PM 03042016070326.ny00227g.zip
d—- 3/9/2016 2:56 PM 03072016060130.ny00227f.pgp.zip -
March 9, 2016 at 12:04 pm #36331
I need this powershell to take these zip move them 1 at a time and process them.
1. find the zip(Works)
2.Move the zip 1 at a time to were the unzip.wsf file can unzip the zip file. (broken)
3.Unzip.wsf unzips file (Works)
3.processes the unzipped files.Works) -
March 9, 2016 at 12:53 pm #36334
Instead of just $_, you should specify the property you want. If you change $_ to $_.FullName, this should work.
Move-item can take pipeline input, so if you ran just `gci -Path "D:\AR Lockbox Checks\*ny*\" -Filter "*.zip" | Move-item -destination D:\somepath` you would be good.
But you're not doing that, you're calling Move-Item in standalone, so you have to be a bit more specific with the cmdlet, to tell it what you're trying to do.
-
AuthorPosts
You must be logged in to reply to this topic.