我创建了一个捕获Get-Volume
到本地文件的小函数。下次该函数运行时,它会将新鲜的输出Get-Volume
与之前保存到文件系统的输出进行比较。
这个函数非常适合服务,但奇怪的是返回一个“不同”的卷,即使我们可以从输出中看到它不是。
function Compare-Volumes{
$Path = "$Env:PROGRAMDATA\VACS\states\"
$File = "volumes.csv"
$Volumes = Get-Volume | Select-Object OperationalStatus, HealthStatus, DriveType, FileSystemType, DedupMode, UniqueId, AllocationUnitSize, DriveLetter, FileSystem, FileSystemLabel, Size
if (![System.IO.File]::Exists($Path+$File)){
$Volumes | Export-CSV -Path $Path$File -Force
}else{
# Load file to object, get differences, submit to API, replace previous snapshot in file with new one
$Snapshot = Import-CSV -Path "$Path$File"
$StatusChanges = Compare-Object -ReferenceObject ($Snapshot) -DifferenceObject ($Volumes) -Property OperationalStatus, HealthStatus, DriveType, FileSystemType, DedupMode, UniqueId, AllocationUnitSize, DriveLetter, FileSystem, FileSystemLabel, Size -IncludeEqual
$StatusChanges
$Volumes | Export-CSV -Path $Path$File -Force
}
}
我的预期结果是一切都返回为相等/不变(==
),因为没有任何属性发生变化,如下面的输出所示。然而由于某种原因,SideIndicator
添加的属性Compare-Object
表示标记为 的卷的值差异Recovery
。
OperationalStatus : Unknown
HealthStatus : Healthy
DriveType : CD-ROM
FileSystemType : Unknown
DedupMode : Disabled
UniqueId : \\?\Volume{2b4803c9-1ebe-11e6-9bed-005056c00008}\
AllocationUnitSize : 0
DriveLetter : E
FileSystem :
FileSystemLabel :
Size : 0
SideIndicator : ==
OperationalStatus : OK
HealthStatus : Healthy
DriveType : Fixed
FileSystemType : NTFS
DedupMode : NotAvailable
UniqueId : \\?\Volume{f688d14f-0ee7-11e5-b210-806e6f6e6963}\
AllocationUnitSize : 4096
DriveLetter : C
FileSystem : NTFS
FileSystemLabel : Windows
Size : 953903214592
SideIndicator : ==
OperationalStatus : Unknown
HealthStatus : Healthy
DriveType : CD-ROM
FileSystemType : Unknown
DedupMode : Disabled
UniqueId : \\?\Volume{f688d152-0ee7-11e5-b210-806e6f6e6963}\
AllocationUnitSize : 0
DriveLetter : D
FileSystem :
FileSystemLabel :
Size : 0
SideIndicator : ==
OperationalStatus : OK
HealthStatus : Healthy
DriveType : Fixed
FileSystemType : NTFS
DedupMode : NotAvailable
UniqueId : \\?\Volume{f688d14e-0ee7-11e5-b210-806e6f6e6963}\
AllocationUnitSize : 4096
DriveLetter :
FileSystem : NTFS
FileSystemLabel : Recovery
Size : 6291451904
SideIndicator : =>
OperationalStatus : OK
HealthStatus : Healthy
DriveType : Fixed
FileSystemType : NTFS
DedupMode : NotAvailable
UniqueId : \\?\Volume{f688d14e-0ee7-11e5-b210-806e6f6e6963}\
AllocationUnitSize : 4096
DriveLetter :
FileSystem : NTFS
FileSystemLabel : Recovery
Size : 6291451904
SideIndicator : <=