VMware Cloud Community
vmk2014
Expert
Expert
Jump to solution

Can we pull the report for Data store free space with respect to VM to data store before taking snapshot ?

Hi All,

I'm planning to take a snapshot for around 400 VM's before VMware tools & VM version upgrade. Can we pull the report for Datastore free space with respect to each VM to data store before taking a snapshot?   Before taking snapshot want to see Datastore having sufficient space.  VM's name will be in C:\Temp\vmliste.txt

E.g. VM1 ---> Data store 1  Free space 15 %   GB - 8

        VM2  --> Datastore 2  Free space 12 %     GB - 6

Thanks

vmk

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, think I got it.

Try like this

Get-VM -Name (Get-Content -Path C:\temp\list.txt) -PipelineVariable vm |

   ForEach-Object -Process {

   Get-Datastore -RelatedObject $_ |

  Select @{N = 'VM'; E = {$vm.Name}}, Name,

  FreeSpaceGB,

   @{N = 'FreeSpace%'; E = {"{0:P}" -f ($_.FreeSpaceGB / $_.CapacityGB)}}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
16 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-VM |

   ForEach-Object -Process {

   Get-Datastore -RelatedObject $_ |

  Select @{N = 'VM'; E = {$vm.Name}}, Name,

  FreeSpaceGB,

   @{N = 'FreeSpace%'; E = {"{0:P}" -f ($_.FreeSpaceGB / $_.CapacityGB)}}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Dear LucD,

I want to pull for a specific list of VM's from C:\temp\list.txt.

Can you please help.

Thanks

vmk

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Change the 1st line to

Get-VM -Name (Get-Content -Path C:\temp\list.txt) |


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

I ran the script but I want the VM's also should be published

VM Name FreeSpaceGB FreeSpace%

VPLX_IND_NP_EE66 828.3535156 20.22%

VPLX_IND_NP_EE5C 1069.270508 26.11%

VPLX_P_P2C2_D2319 908.5410156 75.73%

VPLX_P_P2C3_D2499 704.1796875 58.69%

thanks

vmk

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sorry, don't know what you mean here?
The VM name is in the output.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Yes, VM name in the output.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, think I got it.

Try like this

Get-VM -Name (Get-Content -Path C:\temp\list.txt) -PipelineVariable vm |

   ForEach-Object -Process {

   Get-Datastore -RelatedObject $_ |

  Select @{N = 'VM'; E = {$vm.Name}}, Name,

  FreeSpaceGB,

   @{N = 'FreeSpace%'; E = {"{0:P}" -f ($_.FreeSpaceGB / $_.CapacityGB)}}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Thank you LucD.  it worked but i saw multiple errors on the screen after completing the execution.

pastedImage_0.png

Thanks

vmk

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The error message seem sot indicate that there are VM names in the .txt file that are not found with Get-VM.

Do all the VMs mentioned in the .txt file present?

If it is the intention to have non-existing VMnames in the file, add the -ErrorAction SilentlyContinue on the Get-VM cmdlet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

yes, i included all the 421 VM's which I was looking for snapshot space but surprised to  see the error and I got the output in CSV for all 421 VM's

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Could it be that you are connected to more than 1 vCenter, and that the error comes form one of the other vCenters?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Sorry, I have only one  VCenter.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you take the name of one of those VMs in the error messages, and do a Get-VM with that name, do you get an error?

That error only comes when a VM with the specified name is not found.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

I want to add the Cluster name also in the report. is it possible?

thanks

vmk

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this.

Does this mean that the errors you got are gone?

Get-VM -Name (Get-Content -Path C:\temp\list.txt) -PipelineVariable vm |

   ForEach-Object -Process {

   Get-Datastore -RelatedObject $_ |

  Select @{N = 'VM'; E = {$vm.Name}},

   @{N='Cluster';E={(Get-Cluster -VM $vm).Name}},

  Name, FreeSpaceGB,

   @{N = 'FreeSpace%'; E = {"{0:P}" -f ($_.FreeSpaceGB / $_.CapacityGB)}}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

vmk2014
Expert
Expert
Jump to solution

Yes, today I didn't see any error when executed earlier script.  Smiley Happy

Reply
0 Kudos