资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

获取在SCVMM虚拟机磁盘信息

<#
//-----------------------------------------------------------------------

我们提供的服务有:成都网站制作、成都做网站、外贸营销网站建设、微信公众号开发、网站优化、网站认证、瑶海ssl等。为近1000家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的瑶海网站制作公司

// Copyright (c) {charbelnemnom.com}. All rights reserved.

//-----------------------------------------------------------------------

.SYNOPSIS
Get the list of all Virtual Machines in SCVMM including their disks.

.DESCRIPTION
Get the list of all Virtual Machines in Virtual Machine Manager and enumerate all their drives.

.NOTES
File Name : Get-SCVMVirtualDisk.ps1
Author : Charbel Nemnom
Version : 4.0
Date : 05-February-2018
Requires : PowerShell Version 3.0 or above
OS : Windows Server 2012 R2 or 2016
Product : System Center Virtual Machine Manager 2012 R2 or 2016

.LINK
To provide feedback or for further assistance please visit:
https://charbelnemnom.com

.EXAMPLE
./Get-SCVMVirtualDisk -VMMServerName
This example will get all Virtual Machines including their Virtual Disks from VMM ,
Then calculate the size and percentage used by each VM/VHD(X), total disk size of all VMs and send the report via e-mail.

.EXAMPLE
./Get-SCVMVirtualDisk -VMMServerName -HostGroupName
This example will get all Virtual Machines including their Virtual Disks from a particular VMM Host Group ,
Then calculate the size and percentage used by each VM/VHD(X), total disk size of all VMs and send the report via e-mail.
#>

[CmdletBinding()]
param(
[Parameter(Mandatory=$true,HelpMessage='VMM Server Name')]
[Alias('VMMServer')]
[String]$VMMServerName,

[Parameter(HelpMessage='VMM Host Group Name')]
[Alias('GroupName')]
[String]$HostGroupName

)

Try {

Connect to VMM Server

Write-Verbose "Connecting to VMM server..."
New-CimSession -ComputerName $VMMServerName -ErrorAction Stop | Out-Null
}
Catch {
Write-Error "Cannot connect to VMM Server: $($Error[0].Exception.Message) Exiting"
Exit
}

Variables

$filedate = Get-date
$FromEmail = "VMMReport@domain.net"
$ToEmail1 = "ITAdmin@domain.net"
$ToEmail2 = "ITOperator@domain.net"
$tableColor = "WhiteSmoke"
$DiskSpaceUsed = $null

Establish Connection to SMTP server

$smtpServer = "smtp.mail.net"
$smtpCreds = new-object Net.NetworkCredential("username", "password")
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.UseDefaultCredentials = $false
$smtp.Credentials = $smtpCreds

HTML Style Definition

$report = ""-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">"
$report = ""http://www.w3.org/1999/xhtml">"
$report = ""
$report += "

Get-SCVMVirtualDisk - ScriptVersion: 4.0 | Created By: Charbel Nemnom - CDM MVP | Feedback: https://charbelnemnom.com

"

Report Header

$report = $report + "

Virtual Machines and Virtual Hard Disks Report on: $($VMMServerName)

"

If ($HostGroupName)
{

Report Title

$report = $report + "

Data for VMM Host Group: $($HostGroupName) : $($filedate)

" Write-Verbose "Get VMM Host Group..." $hostGroups = Get-SCVMHostGroup -Name $HostGroupName -VMMServer $VMMServerName If (!$hostGroups) { Write-Error "VMM Host Group named $($HostGroupName) does not exist... Exiting!" Exit } $hostGroups = $hostGroups.AllChildHosts Foreach ($hostGroup in $hostGroups) { $SCVMs += @(Get-SCVirtualMachine -VMMServer $VMMServerName -VMHost $HostGroup.Name) }

}
Else
{
$SCVMs += @(Get-SCVirtualMachine -VMMServer $VMMServerName)
}

Write-Verbose "Generating Report"
Foreach ($SCVM in $SCVMs)
{
$DiskUsed = $null
Write-Verbose "Checking VM: $SCVM Virtual Hard Disks on $($SCVM.HostName)"
$SCVHDs = Get-SCVirtualMachine $SCVM.Name -VMHost $SCVM.HostName | Get-SCVirtualHardDisk | Select-Object Size
Foreach ($SCVHD in $SCVHDs) {
$DiskUsed += $SCVHD.Size
}
$DiskSpaceUsed += $DiskUsed
$report = $report + ""
$report = $report + (Get-SCVirtualMachine $SCVM.Name | Select-Object @{Label="Host Name";Expression={$.VMHost}},@{Label="VM Name";Expression={$.Name}},@{Label="Computer Name";Expression={$.ComputerName}},@{Label="VM Generation";Expression={$.Generation}} | ConvertTo-HTML -as Table -Fragment)
$report = $report + ""
$report = $report + (Get-SCVirtualMachine $SCVM.Name | Get-SCVirtualDiskDrive | Select-Object @{Label="VHD Name";Expression={$.VirtualHardDisk}},@{Label="Controller Type";Expression={$.BusType}},Lun | ConvertTo-HTML -as Table -Fragment)
$report = $report + ""
$report = $report + (Get-SCVirtualMachine $SCVM.Name | Get-SCVirtualHardDisk | Select-Object @{Label="VHD Type";Expression={$.VHDType}},@{Label="VHD Location";Expression={$.Location}},
@{Label="Max Disk Size (GB)";Expression={($_.MaximumSize/1GB)}},@{Label="Disk Space Used (GB)";Expression={"{0:N2}" -f ($_.Size/1GB)}},

@{Label="Disk Space Used (%)";Expression={[math]::Round((($.Size/1GB)/($.MaximumSize/1GB))*100)}}, `
@{Label="Free Disk Space (GB)";Expression={"{0:N2}" -f (($.MaximumSize/1GB) - ($.Size/1GB))}} | ConvertTo-HTML -as Table -Fragment)
$report = $report + "Total Disk Space Used for VM: $($SCVM.Name) in (GB) is $({{0:N2}} -f ($DiskUsed/1GB))" + "
"
$report = $report + "
"
}

Write-Verbose "Calculating Total Disk Space Used for All Virtual Machines..."
$report = $report + "

Total Disk Space Used for All VMs in (GB) is $({{0:N2}} -f ($DiskSpaceUsed/1GB))
"

Finalizing Report

Write-Verbose "Finalizing Report"
$report = $report + ""

Send Email

Write-Verbose "Sending Report"
$email = new-object Net.Mail.MailMessage
$email.Priority = [System.Net.Mail.MailPriority]::High
$email.Subject = "Virtual Machines and Virtual Hard Disks Report: $($filedate)"
$email.From = new-object Net.Mail.MailAddress($FromEmail)
$email.IsBodyHtml = $true
$email.Body = $report
$email.To.Add($ToEmail1)
$email.To.Add($ToEmail2)
$smtp.Send($email)


分享题目:获取在SCVMM虚拟机磁盘信息
网页路径:http://cdkjz.cn/article/jsdohh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220