Powershell 从多个远程服务器中搜索特定文件类型的文件
你能帮我完成我的小命令吗?我写这个命令是为了搜索来自各个地区大约150台远程服务器的文件Powershell 从多个远程服务器中搜索特定文件类型的文件,powershell,command,Powershell,Command,你能帮我完成我的小命令吗?我写这个命令是为了搜索来自各个地区大约150台远程服务器的文件 Invoke-Command -ComputerName (Get-Content F:\Serverlist.txt) -ScriptBlock {dir c:\ -Recurse -File | where {$_.Extension -eq ".pst"} |select Length,LastAccessTime,Name,@{n='Path';e={$_.fullname}},@{n='Owner
Invoke-Command -ComputerName (Get-Content F:\Serverlist.txt) -ScriptBlock {dir c:\ -Recurse -File | where {$_.Extension -eq ".pst"} |select Length,LastAccessTime,Name,@{n='Path';e={$_.fullname}},@{n='Owner';e={$_.getaccesscontrol().owner}}} |Export-Csv F:\files.csv -NoTypeInformation
在这里,我正在C驱动器中搜索来自多个服务器的.PST文件,我想在上面的命令中包括其他驱动器F。
Dir
是Get ChildItem
的别名,您可以通过Get alias Dir
看到这一点
如果使用Get help Get ChildItem-Full
查看帮助,您将看到-Path
接受多个输入:
-Path <String[]>
Specifies a path to one or more locations.
-路径
指定一个或多个位置的路径。
因此,我认为解决办法是替换:
dir c:\
使用此Get ChildItem c:,F:
我还想补充一点,您应该尽可能在提供者级别进行筛选,因为这要快得多。我可能不喜欢文件系统提供商的过滤功能,但对扩展名的过滤非常简单,它可以毫无问题地处理它dirc:\-Recurse-File |其中{$\.Extension-eq.pst}
变成gcic:\,F:\-Include*.pst
是的,你是对的。那更快。谢谢你的提醒:)