Check folders with get-childitem without going to zip files

drClays 151 Reputation points
2021-02-09T09:23:40.647+00:00

Hi all,

I create script who check a lot of directory locations and I've problem when script going to location where I've .zip files. He opening zip files and checking this content. I need to checking directory without going to zip content.

How to do this?

Windows for business Windows Server User experience PowerShell
{count} votes

7 answers

Sort by: Most helpful
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2021-02-09T09:52:04.54+00:00

    Could you please post you script here for better understanding.
    By default and as far as I know get-childitem isn't opening zip files and check/read the content of a zip file.


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

  2. drClays 151 Reputation points
    2021-02-09T09:58:19.51+00:00

    This is my scirpt to check files in Directories. He check file size and Last write time. When he go to directory with zip files, he open it and save it to arrays

        $files = \\filelocation1',
        '\\filelocation2',
        '\\filelocation3',etc...
        $folders = if($files -eq "\\filelocation")
                        {
                        Get-ChildItem -Path $files -Exclude Directory1, Directory2
                        }
                        elseif($files -eq "\\filelocation")
                        {
                        Get-ChildItem -Path $files -Exclude Directory1, Directory2
                        }
                        else
                        {
                        Get-ChildItem -Path $files 
                        }
        $array = @()
        foreach ($folder in $folders)
        {
            $FNDirectorys = $folder.FullName
            $LWTDirectory = $folder.LastWriteTime
    
                foreach($FNDirectory in $FNDirectorys)
                {
                $bakFiles = Get-ChildItem -Path $FNDirectorys
                $bakFilesCheck = Get-ChildItem -Path $FNDirectorys | where {$_.Length -lt 100KB}
                    $checkFileSize = if ($bakFilesCheck.Count -gt 0)
                    {
                    "Check"
                    }
                    else
                    {
                    "Ok"
                    }
                $bakFilesLWT = Get-ChildItem -Path $FNDirectorys | where {$_.LastWriteTime -gt (Get-Date).AddDays(-7)}
                    $checkLWT = if ($bakFilesLWT.Count -lt 1)
                    {
                    "Check"
                    }
                    else
                    {
                    "Ok"
                    }
                }
                $array += [pscustomobject]@{
                    Folder = $FNDirectorys
                    LastWrite = $LWTDirectory
                    Count = $bakFiles.Count
                    CheckFile = $checkFileSize
                    CheckLTW = $checkLWT
                    }
    
        }
    
        $array | Export-Csv 
    
    0 comments No comments

  3. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2021-02-09T15:10:53.113+00:00

    I tested your script on my Windows 10 computer. I just modified the $files variable (C:\1).

    And here the script does not open the zip file to read the content (3.rtf is in the zip file, not in the folder c:\1).

    65903-zipcontent.jpg

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

  4. drClays 151 Reputation points
    2021-02-10T06:30:35.62+00:00

    If it worked, I wouldn't ask about it :)

    This is how look my directory with zip files.
    66207-2021-02-10-07h19-32.png

    And this is how my script show it(this is directory with zip files only).

    66140-2021-02-10-07h20-36.png

    This is correct view what I'll see(this is directories without zip files).

    66232-2021-02-10-07h25-35.png


  5. drClays 151 Reputation points
    2021-02-10T08:42:32.763+00:00

    I noticed where I have a problem.

    When my directory location have folders with files it's work correct, but when in source location I have only files, then he takes all files one at a time, not counting files.

    Now...how to bite it now?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.