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

问题描述

您好


我有一个脚本从计算机列表中搜索.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

}

}

}

}

解决方案

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
}
}
}
}

解决方案


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

05-23 23:01