如何使用 Powershell 在远程服务器上查找 mp3 文件

如何使用 Powershell 在远程服务器上查找 mp3 文件

我已经创建了一个 powershell 脚本来在我的工作站上搜索 mp3 文件。这在我的工作站上成功了,我如何在我的 80 个工作站的网络上运行它?

$strComputers = Get-Content -Path "C:\ARM\computernames.txt"
[bool]$firstOutput = $true
foreach($strComputer in $strComputers)
{
$colFiles = Get-Wmiobject -namespace "root\CIMV2" `
-computername $strComputer `
-Query "Select * from CIM_DataFile `
Where Extension = 'mp3'"
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:\ARM\pstdetails.csv"
$firstOutput = $false
}
else
{
Write-output $output | Out-File -Encoding ascii -filepath "C:\ARM\pstdetails.csv" -append
}
}
}
}

相关内容