I have a folder consisting of 16,497 subfolders containing over 72,000 files of all types, including thousands of image files with BMP, EMF, GIF, JPG, PDF, PNG, TIF, and WMF extensions. The image files are supposed to all have an accompanying DOC file that explains the image in detail. However, I have discovered that not all do. Therefore, I’m trying to write a PowerShell script to find all the image files that do not have DOC files with the same base name and report the FULLNAME to a file called NODOCS.TXT. I will then examine each reported image file to see if it has a misnamed DOC file or if the DOC file is truly missing. (NOTE: I’ve discovered that the person who created all these files didn’t always match the image and DOC files’ base names.)
As a start, I tried writing a script to identify all the image files in all these 16K subfolders. It didn’t work as planned, and I don’t understand what I’ve done wrong.
Here’s what I wrote to try and find all the image files:
$LookHere = "\\VFS1\CompanyShared\ENotebook Directory"
$ExtensionsToCheck = @(
'.bmp'
'.emf'
'.gif'
'.jpg'
'.pdf'
'.png'
'.tif'
'.wmf'
)
Get-ChildItem $LookHere -File -Recurse | Where ({$_.extension -eq $ExtensionsToCheck}) | Select -ExpandProperty FullName
I ran this and got nothing. When I say, “I got nothing,” I mean the script appeared to run, and it didn’t return any error messages, but it also returned no files. So, then I modified it as follows:
$LookHere = "\\VFS1\CompanyShared\ENotebook Directory"
$ExtensionsToCheck = @(
'.bmp'
'.emf'
'.gif'
'.jpg'
'.pdf'
'.png'
'.tif'
'.wmf'
)
Get-ChildItem $LookHere -File -Recurse | Where ({$_.extension -eq "*.pdf"}) | Select -ExpandProperty FullName
I had the same results as above. I made a further modification to my script.
$LookHere = "\\VFS1\CompanyShared\ENotebook Directory\*.pdf"
$ExtensionsToCheck = @(
'.bmp'
'.emf'
'.gif'
'.jpg'
'.pdf'
'.png'
'.tif'
'.wmf'
)
Get-ChildItem $LookHere -File -Recurse | Select -ExpandProperty FullName
This returned about 17,000 PDF files.
I then changed “Where” to “Where-Object” thinking that might make a difference. The script is as follows:
$LookHere = "\\VFS1\companyshared\ENotebook Directory"
$ExtensionsToCheck = @(
'.bmp'
'.emf'
'.gif'
'.jpg'
'.pdf'
'.png'
'.tif'
'.wmf'
)
Get-ChildItem $LookHere -File -Recurse | Where-Object {$_.extension -eq "*.pdf"} | Select -ExpandProperty FullName
Again, the script appeared to run, and I didn’t get any error messages, but it returned no files.
Can someone please explain to me why the scripts don’t work with Where or Where-Object in them?
Also, given how much trouble I’m having even finding the image files, I’m not sure at this point how I’m going to run a comparison of the base names to find matching base names with .doc extensions. Any suggestions or code would be appreciated.