0
votes

Essentially I'm trying to use PowerShell to find files with certain file extensions on a network drive created on or after June 1st of this year. I thought I could do that with the following statement:

Get-ChildItem NETWORKPATH*. -recurse -include .xlsx | Where-Object { $_.CreationTime -ge "06/01/2014" }

I run into 2 problems:

  1. The command only returns files from the root and one folder on the network drive, there's over 100 folders on this network drive
  2. The command returns 3 out of the 5 files created after 6/1/14 and one created well before my creation time date.

I have access to all of the folders on the network drive. When I run Windows 7 search it finds all of the files. It doesn't matter if I run Powershell as administrator or not. It doesn't matter if I run it from my machine (Windows 7) or from one of our 2008 servers. The network drive I'm trying to search through is on a 2003 file server. What am I doing wrong?

3
@StephenP thanks for the prompt response, it looks like issue 2) was a non-issue as the file had a creation date newer than the modified date (which apparently can happen when you copy a file and not move a file).Winski Tech
This still leaves issue 1. It looks like a permissions issue but I get the same results in all of the following cases: 1) logged in as my own user (who has access to at least see all of the files on this drive) and running powershell as admin 2) same as 1 but running the program not as admin 3) logged in on my network admin account running powershell as admin 4) same as 3 but running not as adminWinski Tech
Tried a few more things, none of which helped, including: 1) adding -force. 2) Removing the -include *.xlsx and changing the wildcard on the end of the path to *.xlsx 3) Including the -path then putting my network path in 4) Using the mapped drive or the UNC path in network path sectionWinski Tech

3 Answers

1
votes

Make sure you add a wildcard to your Include parameter. Also you should never use strings for date comparison. See the example of why not here. Try the following:

$testDate = new-object DateTime (2014,06,01)
Get-ChildItem NETWORKPATH*. -recurse -include *.xlsx | Where-Object { $_.CreationTime -ge $testDate }

Also note that files and folders marked as hidden will not show up unless you add a -force to the get-childitem. Not sure if that is part of the issue or not.

0
votes

gci -path PATH -recurse | where {$_.extension -match "xlsx"} was the silver bullet to all of this.

0
votes

This is what I use.

$Extensions = '*.xlsx','*.csv','*.xls'
$path = 'Network path'
Get-ChildItem "$path" -Include $Extensions -Recurse -Force | where {$_.CreationTime -gt 
[datetime]"10/05/2018"} | Select * | Export-Csv -Path C:\TestExcelfiles.csv - 
NoTypeInformation | fl * #format-wide