$_ is not working!

This topic contains 5 replies, has 3 voices, and was last updated by  Stephen Owen 1 year, 6 months ago.

  • Author
  • #36326

    Jose Contreras

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


  • #36327

    Jose Contreras

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

  • #36328

    Bob McCoy

    What do you get if you just run ...

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

    Jose Contreras

    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

  • #36331

    Jose Contreras

    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)

  • #36334

    Stephen Owen

    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.

You must be logged in to reply to this topic.