Automation

 View Only
  • 1.  Script to get memory, cpu and disk allocate

    Posted Jun 29, 2017 08:58 AM

    Hello, Can you suggest a script to get in csv file list of virtual machine, with cpu,memory and disk allocate and in which host they are. Thanks



  • 2.  RE: Script to get memory, cpu and disk allocate

    Posted Jun 29, 2017 09:06 AM

    You mean something like this?

    Get-VM |

    Select Name,@{N='VMHost';E={$_.VMHost.Name}},

        NumCpu,MemoryGB,UsedSpaceGB |

    Export-Csv report.csv -NoTypeInformation -UseCulture



  • 3.  RE: Script to get memory, cpu and disk allocate

    Posted Jun 29, 2017 09:09 AM

    A simple straight one liner would be like this.

    Connect-VIServer 'YourvCenterName'

    Get-VM | Export-Csv -path “c:\reports\vminventory.csv” –NoTypeInformation

    This will export all information regarding VM into CSV file and you can use filter to exclude information you dont want.

    If you are looking for specific information you mentioned, use below command :

    Connect-VIServer 'YourvCenterName'

    Get-VM | select Name, NumCpu, MemoryGB, HardDisks, Host | Export-Csv -path “c:\reports\vminventory.csv” -NoTypeInformation



  • 4.  RE: Script to get memory, cpu and disk allocate

    Posted Jun 29, 2017 09:14 AM

    Afaik there are no HardDisks nor Host properties anymore on a VirtualMachine​ object since PowerCLI 5.0.



  • 5.  RE: Script to get memory, cpu and disk allocate

    Posted Jun 29, 2017 10:43 AM

    Thanks LucD​ for correction as always :smileyhappy:

    Yes I checked these properties are depreciated, and its working with :

    Get-VM | select Name, NumCpu, MemoryGB, ProvisionedSpaceGB, UsedSpaceGB, VMHost | Export-Csv -path “c:\reports\vminventory.csv” -NoTypeInformation

    Whereas :

    ProvisionedSpaceGB = Hard disk space allocated as VMDK.

    UsedSpaceGB = Actual Space used inside VMDK



  • 6.  RE: Script to get memory, cpu and disk allocate

    Posted May 03, 2023 07:32 AM

    Hello LucD,

    I didn't want to open a new threat as is the same topic.

    I would like to get the same output with some more information, a VM with Numcpu, memoryGB, a custom attribute + the vmdk attached to the VM and their corresponding datastore.

    I have code for the 1st part, but I do not know how can I add the get-harddisk | select-object filename, capacityGB to the $report and concatenate the result,

     

    Any hint would be appreciated, thank you.

     

    Get-VM -name "*name*" | ForEach-Object {
    $VM = $_
    $VM | Get-Annotation -CustomAttribute "Roles"|`
    ForEach-Object {

    $Report = "" | Select-Object VM,Value,NumCpu,MemoryGB
    $Report.VM = $VM.Name
    $Report.NumCpu = $VM.NumCpu
    $Report.MemoryGB = $VM.MemoryGB
    $Report.Value = $_.Value
    $Report
    }
    }

     



  • 7.  RE: Script to get memory, cpu and disk allocate

    Posted May 03, 2023 08:06 AM

    Running through all the harddisks is another loop.
    How do you intend to display that harddisk information in the output?
    If you envisage a line per harddisk, there will be a lot of duplicated information (if a VM has more than 1 harddisk).



  • 8.  RE: Script to get memory, cpu and disk allocate

    Posted May 03, 2023 08:11 AM

    yes, that's the idea, it does not bother me to have for example 5 lines showing the same vm name with 5 vmdk files.



  • 9.  RE: Script to get memory, cpu and disk allocate

    Posted May 03, 2023 08:25 AM

    You could do something like this



  • 10.  RE: Script to get memory, cpu and disk allocate

    Posted May 03, 2023 08:34 AM

    Thank you LucD, that worked for me^^



  • 11.  RE: Script to get memory, cpu and disk allocate

    Posted Jun 29, 2017 10:42 AM

    Thanks a lot for explanation, very useful for newbie like me.



  • 12.  RE: Script to get memory, cpu and disk allocate

    Posted Jun 29, 2017 10:53 AM

    Thanks LucD and vijayrana968 for help.