On Error Resume Next
Dim omAPI: Set omAPI = CreateObject("MOM.ScriptAPI")
e.Save
On Error Goto 0
If IsEmpty(omAPI) or e.Number <> 0 Then
WScript.Quit
End If
Dim oWMI
On Error Resume Next
set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pktPrivacy}!\\" & computerName & "\root\Microsoft\Windows\Deduplication")
e.Save
On Error Goto 0
If Not(IsEmpty(oWMI)) Then
On Error Resume Next
Dim dedupVolumes: Set dedupVolumes = oWMI.ExecQuery("SELECT VolumeId, Volume, LastOptimizationTime, LastGarbageCollectionTime, LastScrubbingTime, OptimizedFilesCount, OptimizedFilesSize, InPolicyFilesCount, InPolicyFilesSize, SavingsRate from MSFT_DedupVolumeStatus")
Dim dedupVolume, omBag
Dim lastRunTime: Set lastRunTime = CreateObject ("WbemSCripting.SWbemDateTime")
For Each dedupVolume in dedupVolumes
Set omBag= omAPI.CreatePropertyBag()
Call omBag.AddValue("VolumeId", dedupVolume.VolumeId)
Call omBag.AddValue("Volume", dedupVolume.Volume)
If dedupVolume.LastOptimizationTime <> "null" Then
lastRunTime.Value = dedupVolume.LastOptimizationTime
call omBag.AddValue("DaysSinceLastOptimization", DateDiff("d",lastRunTime.GetVarDate, Now))
Else
call omBag.AddValue("DaysSinceLastOptimization", -1)
End If
If dedupVolume.LastGarbageCollectionTime <> "null" Then
lastRunTime.Value = dedupVolume.LastGarbageCollectionTime
call omBag.AddValue("DaysSinceLastGarbageCollection", DateDiff("d",lastRunTime.GetVarDate, Now))
Else
call omBag.AddValue("DaysSinceLastGarbageCollection", -1)
End If
If dedupVolume.LastScrubbingTime <> "null" Then
lastRunTime.Value = dedupVolume.LastScrubbingTime
call omBag.AddValue("DaysSinceLastScrubbing", DateDiff("d",lastRunTime.GetVarDate, Now))
Else
call omBag.AddValue("DaysSinceLastScrubbing", -1)
End If
Call omBag.AddValue("OptimizedFilesCount", dedupVolume.OptimizedFilesCount)
Call omBag.AddValue("OptimizedFilesSize", dedupVolume.OptimizedFilesSize)
Call omBag.AddValue("InPolicyFilesCount", dedupVolume.InPolicyFilesCount)
Call omBag.AddValue("InPolicyFilesSize", dedupVolume.InPolicyFilesSize)
If dedupVolume.InPolicyFilesCount > 0 Then
Call omBag.AddValue("DedupCompletionPercent", dedupVolume.OptimizedFilesCount / dedupVolume.InPolicyFilesCount * 100)
Else
Call omBag.AddValue("DedupCompletionPercent", 0)
End If
Call omBag.AddValue("SavingsRate", dedupVolume.SavingsRate)
omAPI.AddItem(omBag)
Next
On Error Goto 0
Call omAPI.ReturnItems()
End If
Class Error
Public Description
Public Number
Public Source
Sub Class_Initialize()
Number = 0
End Sub
Sub Save
Description = Err.Description
Number = Err.Number
Source = Err.Source
Err.Clear
End Sub
Sub Raise(strDescription)
Err.Raise Number, Source, strDescription & GetErrorString(Number, Description)
End Sub
End Class