I have a program that returns an exit code of 1 if a text file is empty or if it has a header record and no other contents.
I'm trying to have powershell loop the contents of a folder (text files) into the program, and if the program returns an exit code not equal to 0, move the file to another location. Here's what I have so far:
$files = Get-ChildItem -name C:\SourceFolder
$files | ForEach-Object {C:\TestProgram.cmd $_ } | ForEach-Object { if ($LASTEXITCODE -ne 0) {Move-Item $_.FullName C:\DestFolder} }
It's looping through the source folder fine and running the test program against it (dummy script returning an exit code of 1), and it looks like it's running the if statement correctly, but the $_.FullName after the Move-Item has lost its relationship with the original object (the file read in). It's now just the exit code at this point. I'm probably way off, is this even possible?
Thanks!
Aucun commentaire:
Enregistrer un commentaire