VKernel.CapacityAnalyzer.SMBFileShareDiscovery (Discovery)

Element properties:

TargetMicrosoft.SystemCenter.VirtualMachineManager.2012.VMMManagementServer
EnabledTrue
Frequency14400
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

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

Source Code:

<Discovery ID="VKernel.CapacityAnalyzer.SMBFileShareDiscovery" Enabled="true" Target="SCVMM2012DiscoveryMP!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMManagementServer" ConfirmDelivery="true" Remotable="false" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="VKernel.CapacityAnalyzer.SMBFileShare">
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
<Property TypeID="VKernel.CapacityAnalyzer.SMBFileShare" PropertyID="ShareId"/>
<Property TypeID="VKernel.CapacityAnalyzer.SMBFileShare" PropertyID="Name"/>
<Property TypeID="VKernel.CapacityAnalyzer.SMBFileShare" PropertyID="Size"/>
<Property TypeID="VKernel.CapacityAnalyzer.SMBFileShare" PropertyID="Path"/>
<Property TypeID="VKernel.CapacityAnalyzer.SMBFileShare" PropertyID="StorageVolumeID"/>
</DiscoveryClass>
<DiscoveryClass TypeID="VKernel.CapacityAnalyzer.HostSMBFileShare">
<Property TypeID="VKernel.CapacityAnalyzer.HostSMBFileShare" PropertyID="HostId"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="FileShareJob.ps1" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>14400</IntervalSeconds>
<SyncTime/>
<ScriptName>FileShareDiscovery.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$"
$oDiscoveryData = $oAPI.CreateDiscoveryData(0, $SourceId, $ManagedEntityId);

Import-Module VirtualMachineManager

trap [Exception]
{
$oAPI.LogScriptEvent("FileShareDiscovery.ps1", 102, 2, $_.Exception.Message);
continue;
}

$oAPI.LogScriptEvent("FileShareDiscovery.ps1", 102, 2, "Collecting file share");

#Connecting to VMM Server
$vmm = $null;
$vmm = Get-VMMServer -ComputerName $ComputerName

if ($vmm -ne $null)
{
$provider = Get-SCStorageProvider
foreach ($fileServer in $provider.get_StorageFileServers())
{
foreach ($fileShare in $fileServer.get_StorageFileShares()){
$oAPI.LogScriptEvent("FileShareDiscovery.ps1", 102, 2, "FileShare with principal name: " + $fileShare);
$oInst = $oDiscoveryData.CreateClassInstance("$MPElement[Name='VKernel.CapacityAnalyzer.SMBFileShare']$")
$oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $fileShare.Name);
$oAPI.LogScriptEvent("FileShareDiscovery.ps1", 102, 2, "New ShareID = " + $fileShare.ID.Guid);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.SMBFileShare']/ShareId$", $fileShare.ID.Guid);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.SMBFileShare']/Name$", $fileShare.Name);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.SMBFileShare']/Size$", $fileShare.Capacity.toString());
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.SMBFileShare']/Path$", $fileShare.SharePath);
$oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ComputerName);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.SMBFileShare']/StorageVolumeID$", $fileShare.StorageVolumeID.Guid);
$oDiscoveryData.AddInstance($oInst)
foreach ($hostAssoc in $fileShare.HostAssociations){
$oInst = $oDiscoveryData.CreateClassInstance("$MPElement[Name='VKernel.CapacityAnalyzer.HostSMBFileShare']$")
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.SMBFileShare']/ShareId$", $fileShare.ID.Guid);
$oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ComputerName);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.HostSMBFileShare']/HostId$", $hostAssoc.Host.ID.Guid);
$oDiscoveryData.AddInstance($oInst)
$oAPI.LogScriptEvent("FileShareDiscovery.ps1", 102, 2, "SMB host relation " + $hostAssoc.Host.ID.Guid);
}
foreach ($clusterAssoc in $fileShare.ClusterAssociations){
$oInst = $oDiscoveryData.CreateClassInstance("$MPElement[Name='VKernel.CapacityAnalyzer.HostSMBFileShare']$")
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.SMBFileShare']/ShareId$", $fileShare.ID.Guid);
$oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ComputerName);
$oInst.AddProperty("$MPElement[Name='VKernel.CapacityAnalyzer.HostSMBFileShare']/HostId$", $clusterAssoc.Host.ID.Guid);
$oDiscoveryData.AddInstance($oInst)
$oAPI.LogScriptEvent("FileShareDiscovery.ps1", 102, 2, "SMB host from cluster relation " + $clusterAssoc.Host.ID.Guid);
}
$oAPI.LogScriptEvent("FileShareDiscovery.ps1", 102, 2, "This is new " + $fileShare.Name);
}
}
}

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