SCVMM的Powershell脚本

时间:2016-03-21 05:47:10

标签: powershell

我使用SCVMM的PowerShell脚本获取VMS及其属性的列表。我想计算在一天或一小时内关闭VM的时间。 请帮助我知道如何关闭每个VM的关闭持续时间。下面的脚本每1小时运行一次。

以下是我的剧本。

# CHANGE
# Specify the VMM Server
#Write-Host “Connecting to VMM server.....”
$VMMServer="calo-infvmm-01.calocosn.local"
$a = ((get-date).ToUniversalTime()).ToString("yyyyMMddTHHmmss")

$clouds = Get-SCCloud -VMMServer $VMMServer

#Write-Host “Connected to VMM server successffully..”

$vmHeader = [string]::Concat("VMId",",","SubscriptionId",",","VMName",",","OperatingSystem",",","Memory(MB)",",","CPUCount",",","DiskUsed(GB)",",","DiskAllocated(GB)",",","StorageClassification",",","Owner",",","CreationTime",",","SampleTime",",","Status")
Write-Output $vmHeader

ForEach ($cloud in $clouds) 
{
    $VMs = Get-scVirtualMachine -Cloud $cloud
    ForEach ($VM in $VMs) 
    {
        #if ($VM.Name -ne "TestCCE")
        #{
        #    continue;
        #}
        $size = 0
        $maxSize = 0
        $classification = "Standard"
        #Write-Output $VM
        ForEach ($disk in $VM.VirtualHardDisks) 
        {
            $classification = $disk.Classification
            $size += $disk.Size / 1gb

            $parentDisk = $disk.ParentDisk
            while($parentDisk)
            {
            $size += $parentDisk.Size / 1gb
            $parentDisk = $parentDisk.ParentDisk
            }

            $maxSize += $disk.MaximumSize / 1gb
        }
        # CHANGE
        # After the test works, we will acquire additional variables from VMM.        
        $vmText = [string]::Concat($vm.ID,",",$vm.UserRoleID,",",$vm.Name,",",$vm.OperatingSystem,",",$vm.Memory,",",$vm.CPUCount,",",$size,",",$maxSize,",",$classification,",",$vm.Owner,",",$vm.CreationTime,",",$a,",",$vm.Status)
        Write-Output $vmText
    }
}

1 个答案:

答案 0 :(得分:0)

不幸的是,这不可能,因为它不是由所使用的cmdlet返回的值,也没有我能找到的将显示VM已脱机多久的值。