Hi
I'm unable to find a command to collect the total number of disks and the controller configured on VM?
Can you help me at least with some resources 🙂
You mean something like this?
Get-VM |
Select Name,
@{N='vDisk#';E={(Get-HardDisk -VM $_).Count}},
@{N='Controller#';E={(Get-ScsiController -VM $_).Count}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you try something like this?
$report = @()
foreach ($vm in Get-VM) {
$view = Get-View $vm
$hd = Get-HardDisk -VM $vm
if ($view.config.hardware.Device.Backing.ThinProvisioned -eq $true) {
$row = '' | Select-Object Name, Provisioned, Total, Used, VMDKs, VMDKsize, DiskUsed, Thin, StoragePolicy, 'vDisk#', 'Controller#'
$row.Name = $vm.Name
$row.Provisioned = [math]::round($vm.ProvisionedSpaceGB , 2)
$row.Total = [math]::round(($view.config.hardware.Device | Measure-Object CapacityInKB -Sum).sum / 1048576 , 2)
$row.Used = "{0:N2}GB" -f $vm.UsedSpaceGB
$row.VMDKs = $view.config.hardware.Device.Backing.Filename | Out-String
$row.VMDKsize = $view.config.hardware.Device | Where-Object { $_.GetType().name -eq 'VirtualDisk' } | ForEach-Object { "{0:N2}GB" -f (($_.capacityinKB) / 1MB) } | Out-String
$row.DiskUsed = $vm.Extensiondata.Guest.Disk | ForEach-Object { "{0:N2}GB" -f (($_.Capacity - $_.FreeSpace) / 1GB) } | Out-String
$row.Thin = $view.config.hardware.Device.Backing.ThinProvisioned | Out-String
$row.StoragePolicy = (Get-SpbmEntityConfiguration -HardDisk $hd).StoragePolicy.Name | %{if($_ -eq $null){'Datastore Default'}else{$_}} | Out-String
$row.'vDisk#' = $hd.Count
$row.'Controller#' = (Get-ScsiController -VM $vm).Count
$report += $row
}
}
$report | Sort-Object Name | Export-Csv -Path "D:Thin_Disks.csv"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You mean something like this?
Get-VM |
Select Name,
@{N='vDisk#';E={(Get-HardDisk -VM $_).Count}},
@{N='Controller#';E={(Get-ScsiController -VM $_).Count}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried to add it to this script but I'm getting errors
for sure you can help me but I would like to understand how I can find such information, because I'm checking this 2 references
https://developer.vmware.com/docs/powercli/latest/products/vmwarevsphereandvsan/
https://developer.vmware.com/apis/1355/vsphere
For sure I'm doing something in wrong way 😁
Did you try something like this?
$report = @()
foreach ($vm in Get-VM) {
$view = Get-View $vm
$hd = Get-HardDisk -VM $vm
if ($view.config.hardware.Device.Backing.ThinProvisioned -eq $true) {
$row = '' | Select-Object Name, Provisioned, Total, Used, VMDKs, VMDKsize, DiskUsed, Thin, StoragePolicy, 'vDisk#', 'Controller#'
$row.Name = $vm.Name
$row.Provisioned = [math]::round($vm.ProvisionedSpaceGB , 2)
$row.Total = [math]::round(($view.config.hardware.Device | Measure-Object CapacityInKB -Sum).sum / 1048576 , 2)
$row.Used = "{0:N2}GB" -f $vm.UsedSpaceGB
$row.VMDKs = $view.config.hardware.Device.Backing.Filename | Out-String
$row.VMDKsize = $view.config.hardware.Device | Where-Object { $_.GetType().name -eq 'VirtualDisk' } | ForEach-Object { "{0:N2}GB" -f (($_.capacityinKB) / 1MB) } | Out-String
$row.DiskUsed = $vm.Extensiondata.Guest.Disk | ForEach-Object { "{0:N2}GB" -f (($_.Capacity - $_.FreeSpace) / 1GB) } | Out-String
$row.Thin = $view.config.hardware.Device.Backing.ThinProvisioned | Out-String
$row.StoragePolicy = (Get-SpbmEntityConfiguration -HardDisk $hd).StoragePolicy.Name | %{if($_ -eq $null){'Datastore Default'}else{$_}} | Out-String
$row.'vDisk#' = $hd.Count
$row.'Controller#' = (Get-ScsiController -VM $vm).Count
$report += $row
}
}
$report | Sort-Object Name | Export-Csv -Path "D:Thin_Disks.csv"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
As simple as that 🙂 Thank you
Question : to have the output in separate line this , would you please help me with some clue, I would like to give a try 🙂
Instead of looking at al the Harddisks at once, I would loop over the Harddisks.
Using a loop like this for example
Get-VM -PipelineVariable vm |
Get-Harddisk -PipelineVariable hd |
Foreach-Object -Process {
# Create and populate the object for each Harddisk
}
The PipelineVariable parameter allows you to refer to the objects returned by Get-VM, via $vm, and Get-Harddisk, via $hd.
Also, note that the Get-View is not really needed, you can access the same properties via for example $vm.ExtensionData and $hd.ExtensionData
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I will give atry and keep you posted 🙂
I'm still beginner 😂
We were all beginners at one point in time 😁
The best way to learn is by doing
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
would you please assist me to find reference where I can find ExtensionData?
I checked the link below
https://developer.vmware.com/docs/powercli/latest/products/vmwarevsphereandvsan/
Sure, everything that is available under ExtensionData are in fact the objects listed in the vSphere Web Services API.
For example the content you get when you do
$vm = Get-VM -Name MyVM
$vm.ExtensionData
is documented under the VirtualMachine entry.
Similar for $esx.ExtensionData, $datastore.ExtensionData, $datacenter.ExtensionData, ...
Reading the API Reference might take a while to get used to, but everything is in there.
The objects returned by cmdlets that use a REST API method are documented in the vSphere Automation Reference
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried something like this, the good point is that I didn't received any error message 🙂 but the result is not what's expected
#################################
# vCheck Targeting Variables #
#################################
# Total number of hosts
$TotalVMHosts = Get-VMHost
$TotalVMHostsCount = $TotalVMHosts.count
$CountHosts = $CountHosts + $TotalVMHostsCount
Write-Host "There are $TotalVMHostsCount Hosts in $DefaultVIServer" -Foregroundcolor "Cyan"
# Total number of VMs
$TotalVMs = Get-VM
$TotalVMsCount = $TotalVMs.count
$CountVMs=$CountVMs + $TotalVMsCount
Write-Host "There are $TotalVMsCount Virtual Machines in $DefaultVIServer" -Foregroundcolor "Cyan"
##############################
# Gathering ESXi information #
##############################
Write-Host "Gathering Disk Partition Storage Information"
$Report = @()
$i=0
ForEach ($VM in $TotalVMs){
$i++
Write-Progress -Activity "vCollecting VMs" -Status ("VM: {0}" -f $VM.Name) -PercentComplete ($i/$TotalVMsCount*100) -Id 1 -ParentId 0
#Datacenter info
$datacenter = $vm | Get-Datacenter | Select-Object -ExpandProperty name
#vCenter Server
$vCenter = $vm.ExtensionData.Client.ServiceUrl.Split('/')[2].trimend(":443")
#Cluster info
$cluster = $vm | Get-Cluster | Select-Object -ExpandProperty name
# Total Drives
$TotalDrives = $VM.ExtensionData.Guest.Disk
$TotalDrivesCount = $TotalDrives.count
$j=0
ForEach ($Drive in $VM.ExtensionData.Guest.Disk){
$j++
Write-Progress -Activity "vCollecting Drives" -Status ("Drive: {0}" -f $Drive.DiskPath) -PercentComplete ($j/$TotalDrivesCount*100) -Id 2 -ParentId 1
$Path = $Drive.DiskPath
$Capacity = [math]::Round($Drive.Capacity/ 1GB)
$Freespace = [math]::Round($Drive.FreeSpace / 1GB)
$PercentFree= [math]::Round(((100* ($Drive.FreeSpace))/ ($Drive.Capacity)),0)
$Vmresult = New-Object PSObject
$Vmresult | add-member -MemberType NoteProperty -Name "datacenter" -Value $datacenter
$Vmresult | add-member -MemberType NoteProperty -Name "vCenter Server" -Value $vCenter
$Vmresult | add-member -MemberType NoteProperty -Name "Cluster" -Value $cluster
$Vmresult | add-member -MemberType NoteProperty -Name "Host" -Value $VM.VMHost
$Vmresult | add-member -MemberType NoteProperty -Name "VM Name" -Value $VM.Name
$Vmresult | add-member -MemberType NoteProperty -Name "Disk PATH" -Value $Path
$Vmresult | add-member -MemberType NoteProperty -Name "Capacity(GB)" -Value $Capacity
$Vmresult | add-member -MemberType NoteProperty -Name "Free Space(GB)" -Value $Freespace
$Vmresult | add-member -MemberType NoteProperty -Name "Free Space %" -Value $PercentFree
$report += $Vmresult
}
}
The output for path for example it shot something like this */storage/autodeploy* and I was wondering that I will have the path for the datastore 😂🤣
Everything under $vm.ExtensionData.Guest is information obtained by the VMware Tools from inside the Guest OS.
The Guest OS has no knowledge whatsoever about the virtual environment, including datastores.
That is one reason I suggested earlier to have a loop with Get-Harddisk.
That will return vDisk information, including the Datastore
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks I will try again 🙂