My colleague and I are working on a script to search a list of computers acquired from Active Directory for certain files. We are able to find the files without an issue as seen in the first part of the script.
The challenge is, we need to search within ZipFiles for certain files and out put the computer name to a CSV.
The second half of the script is where the problem lies and I am not sure it the data in the pipeline is being capture properly, and consequently not being exported to CSV.
Any help is tremendously appreciated.
Thanks.
##$computers = Get-ADComputer -filter * | Select -Exp Name $filenames
=Get-Content
"C:\filenamelist.txt"
foreach
($computerin$computers
) {
foreach
($filenamein$filenames
) {
Get-ChildItem
-Recurse-Force\\$computer\c$-ErrorActionSilentlyContinue|Where-Object { ($_.PSIsContainer -eq$false) -and ( $_.Name -eq"$filename") } |Select-ObjectName,Directory|Export-CsvC:\FoundFiles.csv-nti
-append
#$filenames = Get-ChildItem -Path \\$computer\c$ -Recurse "*.*";
}
}
foreach
($filein$filenames
){
if ($filename-eq"$filename"
) {
Where-Object { ($_.PSIsContainer -eq$false) -and ( $_.Name -eq"$filename") } |Select-ObjectName,Directory|Export-CsvC:\FoundFiles.csv-append
}
elseif ($file.Name -eq"*.zip"
) {
# Import dotnet libraries
[Void][Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem'
)
$ObjArray=
@()
if(Test-Path$ZipFile
) {
$RawFiles=[IO.Compression.ZipFile]::OpenRead($zipFile).
Entries
foreach($RawFilein$RawFiles
) {
if ($RawFile.name ="$filename"
) {
Export-CsvC:\FoundFiles.csv-append