File Extension Search

Hi

I have a script to search for .pst from a computer list and save the output list in .csv file, I would like to use the same script to search from multiple file extension i.e. doc,xls,.etc.

Below the script Im using

$strComputers = Get-Content -Path "C:\computernames.txt"
[bool]$firstOutput = $true
foreach($strComputer in $strComputers)
{
$colFiles = Get-Wmiobject -namespace "root\CIMV2" `
-computername $strComputer `
-Query "Select * from CIM_DataFile `
where Extension = 'xlsx' "

foreach ($objFile in $colFiles)
{
if($objFile.FileName -ne $null)
{
$filepath = $objFile.Drive + $objFile.Path + $objFile.FileName + "." `
+ $objFile.Extension;
$query = "ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" `
+ $filepath `
+ "'} WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner"

$colOwners = Get-Wmiobject -namespace "root\CIMV2" `
-computername $strComputer `
-Query $query
$objOwner = $colOwners[0]
$user = $objOwner.ReferencedDomainName + "\" + $objOwner.AccountName
$output = $strComputer + "," + $filepath + "," + $user + "," + $objFile.FileSize/1KB + "," + $objFile.LastModified
if($firstOutput)
{
Write-output $output | Out-File -Encoding ascii -filepath "C:\msofficedetails.csv"
$firstOutput = $false
}
else
{
Write-output $output | Out-File -Encoding ascii -filepath "C:\msofficedetails.csv" -append
}
}
}
}
August 30th, 2015 8:16am

For upgrades to existing scripts pleas contact the author of the script.  We cannot modify scripts found on the Internet.  We can answer specific "How to" questions.

Please see the forum posting guidelines here: https://social.technet.microsoft.com/Forums/en-US/home?forum=ITCG

To learn how to use WMI query syntax look here: https://msdn.microsoft.com/en-us/library/aa394606%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

Free Windows Admin Tool Kit Click here and download it now
August 30th, 2015 8:50am

Ok thank you :(
August 30th, 2015 9:04am

You are welcome.  Many come here thinking this is a help forum ot a free scripts forum. It is really fr admins and technicians or those trying to learn scripting.
Free Windows Admin Tool Kit Click here and download it now
August 30th, 2015 11:59am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics