我正在尝试使用PowerShell和Windows搜索来获取我的磁盘使用情况的一些统计信息。这就是我现在提出的问题:
$sql = "SELECT System.FileExtension, System.Size FROM SYSTEMINDEX WHERE DIRECTORY = 'C:\Users\...\Documents' AND System.FileExtension = '.docx'"
$provider = "provider=search.collatordso;extended properties=’application=windows’;"
$connector = New-Object System.Data.OleDb.OleDbDataAdapter -Argument $sql, $provider
$dataset = New-Object System.Data.DataSet
if ($connector.fill($dataset)) {
$res = $dataset.Tables[0]
$res | Group-Object System.FileExtension |
Select-Object System.FileExtension,
@{Name='Total';Expression={($_.Group | Measure-Object SYSTEM.Size -Sum).Sum}} |
Format-Table
}
这很有效,但看起来很难看。我也发现并尝试过这个:
$sql = "SELECT System.Size FROM SYSTEMINDEX WHERE DIRECTORY = 'C:\Users\...\Documents' AND System.FileExtension = '.docx'"
$provider = "provider=search.collatordso;extended properties=’application=windows’;"
$connector = New-Object System.Data.OleDb.OleDbDataAdapter -Argument $sql, $provider
$dataset = New-Object System.Data.DataSet
if ($connector.fill($dataset)) {
$dataset.Tables[0].Compute("Sum(SYSTEM.Size)")
}
看起来好多了,但却抛出错误:
无法找到" Compute"参数计数:" 1"