简体   繁体   English

在多个驱动器上的服务器上进行Powershell远程文件搜索

[英]Powershell remote file search on servers on multiple drives

So i have a very simple powershell command that is looking for a specific file extension on a remote server. 所以我有一个非常简单的powershell命令,该命令正在远程服务器上寻找特定的文件扩展名。 These remote servers have multiple logical drives (c:,e:,d: ect...) and when i run this command it works against the C: drive of the server but any drives afterwards return a single error Get-ChildItem : Cannot find drive. 这些远程服务器具有多个逻辑驱动器(c:,e:,d:ect ...),当我运行此命令时,它将对服务器的C:驱动器起作用,但是之后所有驱动器都返回一个错误Get-ChildItem:无法找到驱动器。 A drive with the name 'D' does not exist. 名称为“ D”的驱动器不存在。

Command is this, any help is appreciated: 命令是这样,任何帮助表示赞赏:

Get-WmiObject -ComputerName chsccm10 win32_logicaldisk -Filter "DriveType = 3" | Select-Object DeviceID | ForEach-Object {Get-ChildItem ($_.DeviceID + "\") -Include *.log -Recurse } | select VersionInfo

Haven't tested, but maybe something like this: 还没有测试,但是也许是这样的:

$servers = gc c:\serverlist.txt

$results = $servers | %{
    invoke-command -cn $_  -scriptblock {
            gwmi win32_logicaldisk -filter "DriveType = 3" |
            select-object DeviceID |
            Foreach-object {
                Get-childitem ($_.DeviceID + "\") -include *.log -recurse } |
            select VersionInfo}}

$results | out-gridview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM