Author Posts

March 9, 2016 at 10:56 am

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 = 0

gci -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\"


March 9, 2016 at 10:59 am

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

What do you get if you just run ...

gci -Path "D:\AR Lockbox Checks\*ny*\" -Filter "*.zip"

March 9, 2016 at 11:59 am

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
d—- 3/9/2016 2:56 PM
d—- 3/9/2016 2:56 PM
d—- 3/9/2016 2:56 PM
d—- 3/9/2016 2:56 PM

March 9, 2016 at 12:04 pm

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

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.