簡體   English   中英

Powershell腳本,用於搜索多個遠程PC的特定文件

[英]Powershell script to search mutiple remote PC's for specific files

我正在嘗試對包含大量遠程PC的txt文件從PC運行Powershell腳本。 我想針對那些將在特定文件路徑中搜索特定文件名和/或文件擴展名的PC列表運行腳本。

我一直在嘗試將我的txt文件作為變量插入到每個循環中。 我也試圖通過cmdlet“ Get-ChildItem”返回給我的文件名。

到目前為止,我還無法正常工作。 有人能指出我正確的方向嗎? 以下是我迄今為止嘗試過的幾件事......

**

PS C:\Windows\system32> $name= gc env:computername
$computers= get-content -path c:\users\person\Desktop\book2.txt
$csvfile = "c:\temp\$name.csv"
foreach ($computer in $computers) {Get-ChildItem -recurse -filter "C:\Users\*.locky"} 
export-csv -filepath $csvfile

**

*

Get-ChildItem : Second path fragment must not be a drive or UNC name.
Parameter name: path2
At line:4 char:36
+ foreach ($computer in $computers) {Get-ChildItem -recurse -filter "C:\Users\*.lo ...
+                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (C:\Windows\system32:String) [Get-ChildItem], Argume 
   ntException
    + FullyQualifiedErrorId : DirArgumentError,Microsoft.PowerShell.Commands.GetChildItemCommand

Export-Csv : A parameter cannot be found that matches parameter name 'filepath'.
At line:5 char:12
+ export-csv -filepath $csvfile
+            ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Export-Csv], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand

*

C:\Windows\system32> ForEach ($system in (Get-Content C:\temp\Book2.txt))

if  ($exists in (Test-Path \\$system\c$\Users\*.locky))
{
    Get-Command $exists | fl Path,FileVersion | Out-File c:\temp\results.csv -Append
} 
At line:1 char:53
+ ForEach ($system in (Get-Content C:\temp\Book2.txt))
+                                                     ~
Missing statement body in foreach loop.
At line:3 char:14
+ if  ($exists in (Test-Path \\$system\c$\Users\*.locky))
+              ~~
Unexpected token 'in' in expression or statement.
At line:3 char:14
+ if  ($exists in (Test-Path \\$system\c$\Users\*.locky))
+              ~~
Missing closing ')' after expression in 'if' statement.
At line:3 char:55
+ if  ($exists in (Test-Path \\$system\c$\Users\*.locky))
+                                                       ~
Unexpected token ')' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingForeachStatement

Get-ChildItem cmdlet中的 -filter參數錯誤。 下一個代碼段應該工作:

foreach ($computer in $computers) {"\\$computer\C$\Users"|`
    Get-ChildItem -recurse -filter "*.locky"}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM