0

check users in $directory recursive and if no files contain extension JPG,PNG etc then run the results with sigcheck excluding those files?

$directory = dir E:\Users 
$SigcheckPath = "C:\Windows\temp\sigcheck.exe"
$path1 = "download"
$path2 = "documents"

foreach ($dir in $directory) {
    $filepath = Get-ChildItem E:\Users\$dir\downloads -recurse | where {! $_.PSIsContainer}
    foreach ($file in $filepath) {
        if ($file -notmatch '.jpg|.png|.gif') { 
            & $SigcheckPath -nobanner -a -h -s -v -vt -c F:\Users\$dirz\downloads > C:\Users\Admin\Desktop\$dir.csv 
        }
    }
}

It should give output to a single file with .csv all the results for user for that specific directory!

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • Change `>` to `>>`? – Mathias R. Jessen Jul 17 '19 at 15:57
  • It didn't work with ```>>``` – Ismail Kaleem Jul 17 '19 at 17:06
  • `>>` appends rather than overwrites – Mathias R. Jessen Jul 17 '19 at 17:08
  • It's not going through the loop replacing directory in F:\users\$dir\downloads ? It shud actually check Users directory and iterate with all the users. example F:\users\aaa\downloads F:\users\bbb\downloads . I am not sure how to get it to iterate the $dir values; rest of the script works fine and thanks for ```>>``` – Ismail Kaleem Jul 17 '19 at 17:36
  • You need to change `foreach ($dir in $directory)` to `foreach ($dir in $directory.Name)` – AdminOfThings Jul 17 '19 at 18:29
  • I got it to work with this ```foreach ($dir in $directory) { $filepath = Get-ChildItem E:\Users\$dir\Downloads -Recurse -Attributes !Directory foreach ($file in $filepath){ $file | Where-Object { $_.Fullname -notmatch '.gif|.jpg|.png|.txt' } | Select -Expand FullName } }``` – Ismail Kaleem Jul 17 '19 at 19:50

0 Answers0