Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

inconsistent behavior of "where" filter command in remote powershell session

$
0
0

I've got a simple powershell script I've written to do a gpo backup (backup-gpo) to a remote file share, and then I launch a remote powershell session with "invoke-command" where I zip up the results of the gpo backup, then delete the gpo backups once the files are safely zipped.

What I'm seeing, and I've never seen before, is very inconsistent results in the file filtering statements.  I use the following line twice in my code to find the files written by the GPO backup:

 Get-ChildItem -Force | ? {($_.lastwritetime.date -eq (Get-Date).date) -and ($_.name -notlike "*.zip")}

The first time it finds the files to zip, the second time it finds the files to delete.  It's a copy/paste, so it's the exact same code.

The weirdness that happens is some nights, it works fine, and both filters match what they should.  The GPO backup results are found, zipped, and then deleted.  Other nights, the first filter will match all old *.zip files (the exact opposite of the filter), and zip them up - then the "delete" filter, which is the exact same code, will match correctly and delete the GPO backup results that should have been zipped but weren't.

Last night the first filter matched correctly, and then the second filter matched the date portion of the filter, ignored the *.zip portion, and deleted everything in the target folder from that day. 

Anyone seen anything like this?


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>