哪个命令用于获取多个服务器的每个集群字节数和每个文件记录段数据的字节数?

Which command to use for getting Bytes per cluster and Bytes per File record segment data for multiple servers?

我想为 50 多台服务器生成每个集群的字节数和每个文件的字节数记录段数据到 excel sheet(对于驱动器 D)

我知道命令“Fsutil fsinfo ntfsinfo [驱动器号:]”提供了此信息,但仅适用于本地系统。

我试过写这个但是没用。

"输入-PSSession Server1

Fsutil fsinfo ntfsinfo D:

退出-PSSession

然后我手动执行了每个命令,它正在运行。

任何人都可以帮我创建一个脚本来一次性获取 50 个服务器的上述数据。

谢谢

继续我的评论,您可以为此使用 cmdlet Invoke-Comand:

# you may already have admin permissions on each of the servers, but if not, get craedentials for someone that has
$adminCreds = Get-Credential -Message 'Please add your admin credentials to get server information'

# your list of server names here
$servers    = 'Server01', 'Server02'  # etc. 

# next use 'Invoke-Command' to have each server run the code
$result = Invoke-Command -ComputerName $servers -Credential $adminCreds -ScriptBlock {
    # have each server run the Fsutil command, and return that as PsCustomObject for convenience
    # instead of an array of lines. 
    # to use ConvertFrom-StringData in PowerShell < 7.x, you need to replace the first colon with a equals sign
    # PowerShell versions above 5.1 can use parameter  -Delimiter '='
    [PsCustomObject]((Fsutil fsinfo ntfsinfo D:) -replace '(?<!:.*):', '=' -join "`r`n" | ConvertFrom-StringData)
}

现在您可以将整个结果保存为 CSV 或限制为您需要的属性,例如

$result | Select-Object PSComputerName, 'Bytes Per Cluster', 'Bytes Per FileRecord Segment' | Export-Csv -Path 'X:\serverInfo.csv' -NoTypeInformation

如果您不确定是否可以访问所有服务器,请执行循环:

$result = foreach ($server in $servers) {
    # test if the server can be reached
    if (Test-Connection -ComputerName $server -Count 1 -Quiet) {
        Invoke-Command -ComputerName $server -Credential $adminCreds -ScriptBlock {
            # have each server run the Fsutil command, and return that as PsCustomObject for convenience
            # instead of an array of lines. 
            # to use ConvertFrom-StringData in PowerShell < 7.x, you need to replace the first colon with a equals sign
            # PowerShell versions above 5.1 can use parameter  -Delimiter '='
            [PsCustomObject]((Fsutil fsinfo ntfsinfo D:) -replace '(?<!:.*):', '=' -join "`r`n" | ConvertFrom-StringData)
        }
    }
    else {
        Write-Warning "Server $server is off-line!"
    }
}

正则表达式详细信息:

(?<!        Assert that it is impossible to match the regex below with the match ending at this position (negative lookbehind)
   :        Match the character “:” literally
   .        Match any single character
      *     Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
)          
:           Match the character “:” literally