Modul zdroje dat zprostředkovatele místa na diskovém oddílu verze 2
Microsoft.Windows.HyperV.DiskPartitionSpaceProviderDataSourceModuleV2 (DataSourceModuleType)
Element properties:
Member Modules:
Overrideable Parameters:
Source Code:
<DataSourceModuleType ID="Microsoft.Windows.HyperV.DiskPartitionSpaceProviderDataSourceModuleV2" Accessibility="Public" RunAs="System!System.PrivilegedMonitoringAccount" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="0" name="SyncTime" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.SimpleScheduler">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime>$Config/SyncTime$</SyncTime>
</DataSource>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>HyperVMonitoring+GetDiskPartitionSpaceV2.ps1</ScriptName>
<ScriptBody><Script>
#Copyright (c) Microsoft Corporation. All rights reserved.
param($ComputerIdentity)
# Common Functions
function IsHigherThanWin2008
{
$osVersion = New-Object "Version" ([Environment]::OSVersion.Version.Major -As [Int32]), ([Environment]::OSVersion.Version.Minor -As [Int32]);
$osVersionTill2008=New-Object "Version" 6,1;
if ($osVersion -gt $osVersionTill2008)
{
return $true;
}
else
{
return $false;
}
}
function ThrowScriptError
{
param($msg, $errorDetails)
$errorMsg = $msg + $errorDetails;
$oApi.LogScriptEvent("HyperVMonitoring+GetDiskPartitionSpaceV2.ps1", 1000, 1, $errorMsg);
}
function ThrowScriptInfo
{
param($msg)
$oApi.LogScriptEvent("HyperVMonitoring+GetDiskPartitionSpaceV2.ps1", 1000, 4, $msg);
}
function GetPercent
{
param($usage, $capacity)
$percent = 0;
if ($capacity -ne 0)
{
$percent = [Math]::Round(($usage * 100) / $capacity);
}
$percent;
}
# End Common Functions
if ($ComputerIdentity -eq $null)
{
ThrowScriptError -msg "Invalid parameters passed to GetDiskPartitionSpaceV2.ps1" -errorDetails $null
}
$oAPI = new-object -comObject "MOM.ScriptAPI"
$oFile = new-object -comObject "Scripting.FileSystemObject"
$namespace = "root/virtualization/v2";
if ($oFile -ne $null)
{
$error.Clear();
if(IsHigherThanWin2008)
{
$virtualMachineList = @(gcim -Query "SELECT Name, ElementName FROM MSVM_ComputerSystem" -namespace $namespace -ComputerName $ComputerIdentity);
$hostComputerName = @(gcim Win32_ComputerSystem -Property Name -ComputerName $ComputerIdentity);
}
else
{
$virtualMachineList = @(gwmi -Query "SELECT Name, ElementName FROM MSVM_ComputerSystem" -namespace $namespace -ComputerName $ComputerIdentity);
$hostComputerName = @(gwmi Win32_ComputerSystem -ComputerName $ComputerIdentity);
}
foreach ($oVirtualMachine in $virtualMachineList)
{
if ($oVirtualMachine.Name.ToLowerInvariant() -eq $hostComputerName.Name.ToLowerInvariant())
{
continue;
}
$oPropertyBag = $oAPI.CreatePropertyBag();
$oPropertyBag.AddValue("Name", $oVirtualMachine.Name);
$query = "select InstanceID, HostResource, ElementName from Msvm_StorageAllocationSettingData where InstanceID LIKE 'Microsoft:" + $oVirtualMachine.Name + "%'";
if(IsHigherThanWin2008)
{
$vhds = @(gcim -Query $query -Namespace $namespace -ComputerName $ComputerIdentity)
$vhdsvc = @(gcim -query "SELECT * FROM Msvm_ImageManagementService" -Namespace $namespace -ComputerName $ComputerIdentity);
}
else
{
$vhds = @(gwmi -Query $query -Namespace $namespace -ComputerName $ComputerIdentity)
$vhdsvc = @(gwmi -query "SELECT * FROM Msvm_ImageManagementService" -Namespace $namespace -ComputerName $ComputerIdentity);
}
foreach ($vhd in $vhds)
{
$deviceID = ""
if ($vhd.InstanceID -ne $null)
{
$deviceID = $vhd.InstanceID;
}
$filePath = ""
$driveType = ""
$deviceName = "Hard Disk"
$hostResourceArray = $vhd.HostResource;
if ($hostResourceArray -ne $null -and $vhdsvc -ne $null)
{
$filePath = $hostResourceArray[0];
$outParams = Invoke-CimMethod -InputObject $vhdsvc[0] -Methodname GetVirtualHardDiskSettingData -Arguments @{Path=$filePath};
$xmlDoc = new-object -comObject 'Microsoft.XMLDOM';
$xmlDoc.async = "false";
$xmlDoc.loadXML($outParams.SettingData)
$xPath = "/INSTANCE/PROPERTY[@NAME='Type']/VALUE/child:text()"
$node = $xmlDoc.selectSingleNode($xPath)
if ($node -ne $null)
{
if ($node.Text -ne "")
{
$driveType = $node.Text;
}
}
}
$MEGABYTE = 1048576; # 1024 *1024
$TotalSpace = 0; $UsedSpace = 0; $FreeSpace = 0; $diskMonitor = "false";
if ($filePath -ne $null)
{
$diskMonitor = "true";
$driveLetter = $oFile.GetDriveName($filePath);
if ($error -ne $null)
{
$errMsg = "Failed to GetDriveName " + $filePath;
ThrowScriptError -msg $errMsg -errorDetails $error
continue;
}
#Get the logical drive
$drive = $oFile.GetDrive($driveLetter);
if ($error -ne $null)
{
$errMsg = "Failed to GetDrive " + $driveLetter;
ThrowScriptError -msg $errMsg -errorDetails $error
# Set monitoring off for clustering
if ($driveType -ne "3" -and $driveType -ne "4")
{
$diskMonitor = "false";
}
}
else
{
$TotalSpace = $drive.TotalSize/$MEGABYTE;
$FreeSpace = $drive.FreeSpace/$MEGABYTE;
$UsedSpace = $TotalSpace-$FreeSpace;
$UsedPercent = GetPercent -usage $UsedSpace -capacity $TotalSpace;
$propName = $deviceID + ".VHDName"; $oPropertyBag.AddValue($propName, $deviceName);
$propName = $deviceID + ".UsedSpacePercent"; $oPropertyBag.AddValue($propName, [int]$UsedPercent);
$propName = $deviceID + ".TotalSpace"; $oPropertyBag.AddValue($propName, [int]$TotalSpace);
$propName = $deviceID + ".FreeSpace"; $oPropertyBag.AddValue($propName, [int]$FreeSpace);
$propName = $deviceID + ".UsedSpace"; $oPropertyBag.AddValue($propName, [int]$UsedSpace);
$propName = $deviceID + ".Monitor"; $oPropertyBag.AddValue($propName, $diskMonitor);
}
}
}
$oPropertyBag
}
if ($error -eq $null -or $error.Count -eq 0)
{
$errormsg = "Successfully created Disk space property bag instances";
ThrowScriptInfo -msg $errormsg
}
else
{
$errormsg = "Error creating Disk space property bag instances "
ThrowScriptError -msg $errormsg -errorDetails $error
$error.Clear();
}
}
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>ComputerIdentity</Name>
<Value>$Target/Host/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="Filter" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='Name']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Target/Property[Type="HVLib!Microsoft.Windows.HyperV.VirtualMachine"]/VirtualMachineId$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<Composition>
<Node ID="Filter">
<Node ID="Script">
<Node ID="Scheduler"/>
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>