• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 80
  • Last Modified:

PowerCLI to display VMware disk

Any idea how to server the disk size and free space for VMware server (not the VM guests) with PowerCLI ?

Thx
0
AXISHK
Asked:
AXISHK
  • 2
1 Solution
 
Luciano PatrãoICT Senior Infraestructure  Engineer  Commented:
Hi,

Can you elaborate more what you plan to display?

VMware server? VMware workstation?? ESXi?? System partitions?? Datastores?
0
 
AXISHKAuthor Commented:
I want to check the disk size for my VMware servers and automate with PowerCLI to send it through email.

Thx

VMDisk.png
0
 
Luciano PatrãoICT Senior Infraestructure  Engineer  Commented:
Hi

Again, VMware servers can lot of things and also disk.

But with the image I can notice that you want to display datastore information.

I use one of Luc Dekens script and make some changes to your needs.

#########################################################################################
# Created by: Luciano Patrão (using Luc Dekens original script to display datastore)   	#
# Date: 12-05-2018   																	#
# List Datastore space and send report by email  										#
#########################################################################################

$server = "vCenter/ESXi"
$user = "user"
$pwd = "password" 

Connect-VIServer $server -User $user -Password $pwd
cls

$body = Get-Datastore | Select @{N='Datastore';E={

        $script:p = [math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100,1)
        if($p -lt 70){"#fg#$($_.Name)#fe#"}
        elseif($p -lt 90){"#fy#$($_.Name)#fe#"}
        else{"#fr#$($_.Name)#fe#"}}},
		
    @{N='CapacityGB';E={[math]::Round($_.CapacityGB,1)}},
    @{N='FreeSpaceGB';E={[math]::Round($_.FreeSpaceGB,1)}},
    @{N='UsedPercent';E={$script:p}} | ConvertTo-Html
	
$body = $body.Replace('#fg#','<font color=green>').Replace('#fy#','<font color=yellow>').Replace('#fr#','<font color=red>').Replace('#fe#','</font>')

$from = 'from@domain.com' 
$to = 'from@domain.com' 
$smtp = "smtp.domain.com" 
$sub = 'Datastore Report' 
$body = $body | Out-String
$secpasswd = ConvertTo-SecureString "email password" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential($from, $secpasswd)
Send-MailMessage -To $to -From $from -Subject $sub -Body $body -Credential $mycreds -SmtpServer $smtp -DeliveryNotificationOption Never -BodyAsHtml

Open in new window


Hope this helps

Jail
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now