文件扩展名搜索 [英] File Extension Search

查看:91
本文介绍了文件扩展名搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好


我有一个脚本从计算机列表中搜索.pst并将输出列表保存在.csv文件中,我想使用相同的脚本来从多个文件扩展名搜索,即doc,xls,... .etc。


在我正在使用的脚本下面


$ 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`

其中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)

{

写入输出$输出| Out-File -Encoding ascii -filepath" C:\ msofficedetails.csv"

$ firstOutput = $ false

}

else

{

写输出$输出| Out-File -Encoding ascii -filepath" C:\ msofficedetails.csv" -bpend

}

}

}

}

解决方案

要升级现有脚本,请与脚本的作者联系。 我们无法修改在互联网上找到的脚本。 我们可以回答具体的"如何"问题。


请在此处查看论坛发帖指南:
https://social.technet.microsoft.com/Forums/en-US/home?forum=ITCG


要了解如何使用WMI查询语法在这里看:
https ://msdn.microsoft.com/en-us/library/aa394606%28v=vs.85%29.aspx?f = 255& MSPPError = -2147217396



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 I’m 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
}
}
}
}

解决方案

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


这篇关于文件扩展名搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆