PowerShell 碎片整理分析返回 NULL 值

问题描述 投票:0回答:1

PowerShell 碎片整理分析返回 NULL 值

$computer = "Server"
$drives = Invoke-Command -ComputerName $computer -ScriptBlock { Get-PSDrive -PSProvider FileSystem | Select-Object @{n = "Name"; e = { $_.Root.TrimEnd("\") } } }
$drives.Name | ForEach-Object {
    Write-Host $_
    Invoke-Command -ComputerName $computer -ScriptBlock { param($_) 
        $volume = Get-WmiObject -Class Win32_Volume -Filter "DriveLetter = '$_'"
        Write-Host $volume
        $fragmentation = $volume.DefragAnalysis() 
        $Props = @{
            FragmentationStatusFor = $($volume.Name)
            TotalFragmentedFiles   = $($fragmentation.TotalFiles)
            TotalFragmentedBytes   = $($fragmentation.TotalBytes)
        }
        New-Object -TypeName PSObject -Property $Props
    } -ArgumentList $_, $volume
} | Select-Object * | Write-DbaDataTable -SqlInstance SomeServer -Database SomeDB -Schema GET -Table DbaDefragAnalysis -AutoCreateTable -Confirm -KeepNulls -bulkCopyTimeOut 180 -ErrorAction Continue -Verbose -EnableException;

TotalFragmentedFiles 不返回任何值 TotalFragmentedBytes 不返回任何值

windows powershell hard-drive
1个回答
0
投票

您正在尝试检索不存在的

Win32_DefragAnalysis
WMI 类的属性,请检查 Microsoft Win32_DefragAnalysis 文档,没有名为
TotalFragmentedFiles
TotalFragmentedBytes
的属性,这就是为什么您没有得到返回值的原因。

要获得这些值,您可能应该遵循 MS 文档的这篇文章

© www.soinside.com 2019 - 2024. All rights reserved.