VKernel.CapacityAnalyzer.VirtualMachineSnapshotDiscovery (Discovery)

Element properties:

TargetMicrosoft.SystemCenter.VirtualMachineManager.2012.HyperVHost
EnabledTrue
Frequency3600
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
VmSnapshotPowerShellDiscovery DataSource Microsoft.Windows.TimedPowerShell.DiscoveryProvider Default

Source Code:

<Discovery ID="VKernel.CapacityAnalyzer.VirtualMachineSnapshotDiscovery" Enabled="true" Target="SCVMM2012DiscoveryMP!Microsoft.SystemCenter.VirtualMachineManager.2012.HyperVHost" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="VKernel.CapacityAnalyzer.VmSnapshot">
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshot" PropertyID="Name"/>
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshot" PropertyID="Description"/>
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshot" PropertyID="AddedTime"/>
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshot" PropertyID="ModifiedTime"/>
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshot" PropertyID="MarkedForDeletion"/>
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshot" PropertyID="SnapshotID"/>
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshot" PropertyID="ParentSnapshotID"/>
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshot" PropertyID="VMName"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="VKernel.CapacityAnalyzer.VmSnapshotFile">
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshotFile" PropertyID="VMMId"/>
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshotFile" PropertyID="Location"/>
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshotFile" PropertyID="SizeBytes"/>
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshotFile" PropertyID="Modified"/>
<Property TypeID="VKernel.CapacityAnalyzer.VmSnapshotFile" PropertyID="Created"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="VmSnapshotPowerShellDiscovery" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>3600</IntervalSeconds>
<SyncTime/>
<ScriptName>VmSnapshotDiscovery.ps1</ScriptName>
<ScriptBody><Script>
$oAPI = new-object -comObject "MOM.ScriptAPI"
$SourceId = "$MPElement$"
$ManagedEntityId = "$Target/Id$"
$ComputerName = "$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$"
$VmmId = "$Target/Property[Type="SCVMMLibraryMP!Microsoft.SystemCenter.VirtualMachineManager.VMHost"]/VMMId$"

$oDiscoveryData = $oAPI.CreateDiscoveryData(0, $SourceId, $ManagedEntityId);
trap [Exception]
{
$oAPI.LogScriptEvent("VmSnapshotDiscovery.ps1", 151, 2, $_.Exception.Message);
continue;
}
$oDiscoveryData = $oAPI.CreateDiscoveryData(0, $SourceId, $ManagedEntityId);
$snapshots = Get-VM | Get-VMSnapshot
foreach($snap in $snapshots)
{
$VmGuid = $snap.VMId.ToString()
$oInst = $oDiscoveryData.CreateClassInstance("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshot']$")

$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshot']/SnapshotID$", $snap.Id.ToString());
$oInst.AddProperty("$MPElement[Name='SCVMMLibraryMP!Microsoft.SystemCenter.VirtualMachineManager.VMHost']/VMMId$", $VmmId);
$oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ComputerName);

$oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $snap.Name);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshot']/Name$", $snap.Name);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshot']/AddedTime$", $snap.CreationTime);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshot']/MarkedForDeletion$", $snap.IsDeleted);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshot']/VMName$", $snap.VMName);
if($snap.ParentSnapshotId)
{
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshot']/ParentSnapshotID$", $snap.ParentSnapshotId.ToString());
}

$oDiscoveryData.AddInstance($oInst)

foreach($drive in $snap.HardDrives)
{
$file = Get-ChildItem $drive.Path

$oInst = $oDiscoveryData.CreateClassInstance("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshotFile']$")

$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshotFile']/VMMId$", $drive.VMId.ToString());
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshot']/SnapshotID$", $snap.Id.ToString());
$oInst.AddProperty("$MPElement[Name='SCVMMLibraryMP!Microsoft.SystemCenter.VirtualMachineManager.VMHost']/VMMId$", $VmmId);
$oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ComputerName);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshotFile']/Location$", $drive.Path);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshotFile']/SizeBytes$", $file.Length);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshotFile']/Modified$", $file.LastWriteTime);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.VmSnapshotFile']/Created$", $file.CreationTime);

$oDiscoveryData.AddInstance($oInst)
}
}

# Return the discovery data by calling the variable
$oDiscoveryData
</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</Discovery>