<#
//-----------------------------------------------------------------------
// 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 <VMMServerName>
This example will get all Virtual Machines including their Virtual Disks from VMM <VMMServerName>,
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 <VMMServerName> -HostGroupName <HostGroupName>
This example will get all Virtual Machines including their Virtual Disks from a particular VMM Host Group <HostGroupName>,
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 {
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
}
$filedate = Get-date
$FromEmail = "VMMReport@domain.net"
$ToEmail1 = "ITAdmin@domain.net"
$ToEmail2 = "ITOperator@domain.net"
$tableColor = "WhiteSmoke"
$DiskSpaceUsed = $null
$smtpServer = "smtp.mail.net"
$smtpCreds = new-object Net.NetworkCredential("username", "password")
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.UseDefaultCredentials = $false
$smtp.Credentials = $smtpCreds
$report = "<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN
" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
">"
$report = "<html xmlns="http://www.w3.org/1999/xhtml
"><body>"
$report = "<style>"
$report = $report + "TABLE{border-width:2px;border-style: solid;border-color: #C0C0C0 ;border-collapse: collapse;width: 100%}"
$report = $report + "TH{border-width: 2px;padding: 0px;border-style: solid;border-color: #C0C0C0 ;text-align: left}"
$report = $report + "TD{border-width: 2px;padding: 0px;border-style: solid;border-color: #C0C0C0 ;text-align: left}"
$report = $report + "TD{border-width: 2px;padding: 0px;border-style: solid;border-color: #C0C0C0 ;text-align: left}"
$report = $report + "H1{font-family:Calibri;}"
$report = $report + "H2{font-family:Calibri;}"
$report = $report + "Body{font-family:Calibri;}"
$report = $report + "</style>"
$report += "<center><p style=""font-size:12px;color:#BDBDBD"">Get-SCVMVirtualDisk - ScriptVersion: 4.0 | Created By: Charbel Nemnom - CDM MVP | Feedback: https://charbelnemnom.com</p></center>"
$report = $report + "<h2>Virtual Machines and Virtual Hard Disks Report on: $($VMMServerName)</h2>"
If ($HostGroupName)
{
$report = $report + "<h3>Data for VMM Host Group: $($HostGroupName) : $($filedate)</h3>"
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 + "<style>TH{background-color:Indigo}TR{background-color:$($tableColor)}</style>"
$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 + "<style>TH{background-color:Blue}TR{background-color:$($tableColor)}</style>"
$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 + "<style>TH{background-color:DarkGreen}TR{background-color:$($tableColor)}</style>"
$report = $report + (Get-SCVirtualMachine $SCVM.Name | Get-SCVirtualHardDisk | Select-Object @{Label="VHD Type";Expression={$.VHDType}},@{Label="VHD Location";Expression={$.Location}}, <br/>@{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 + "<B>Total Disk Space Used for VM: $($SCVM.Name) in (GB) is $({{0:N2}} -f ($DiskUsed/1GB))</B>" + " <br>"
$report = $report + " <br>"
}
Write-Verbose "Calculating Total Disk Space Used for All Virtual Machines..."
$report = $report + "<h5><B>Total Disk Space Used for All VMs in (GB) is $({{0:N2}} -f ($DiskSpaceUsed/1GB))</B></h5>"
Write-Verbose "Finalizing Report"
$report = $report + "</body></html>"
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)
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章标题:获取在SCVMM虚拟机磁盘信息-创新互联
网址分享:https://www.cdcxhl.com/article0/dgsiio.html
成都网站建设公司_创新互联,为您提供域名注册、定制开发、网站制作、手机网站建设、网站维护、App设计
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联