PowerCLI

 View Only
  • 1.  Export list of vms with objet and createdtime

    Posted Nov 23, 2021 03:23 PM

    Hi,

    i need help to export the list of vms with diferents elements like harddisk, guestos, tag,... and i wan't to add a new colon with the created date of the vm, here is th script that i use, it work fine for all except the created date of the vm,

     

    Get-Module -Name VMware* -ListAvailable | Import-Module
    
    Connect-viserver myvcenter -user administrator -pass password123
    
    $report = foreach($esx in Get-VMHost){
    
    Get-VM -Location $esx |
    
    Select @{N='VMHost';E={$esx.Name}},Name,PowerState,PortGroupName,
    
    @{n="HardDiskSizeGB"; E={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}},
    
    @{N='GuestOS';E={$_.Guest.OSFullName}},
    
    @{N='VeeamBackupJob';E={(Get-TagAssignment -Entity $_ -Category (Get-TagCategory -Name 'VeeamBackupJob')).Tag.Name -join '|'}},
    
    @{N='Criticite';E={(Get-TagAssignment -Entity $_ -Category (Get-TagCategory -Name 'Criticite')).Tag.Name -join '|'}},
    
    @{N='CreatedTime';E={$_.CreatedTime.ToString("ddMMyyyy")}},
    
    @{N='Notes';E={$_.Notes.Replace("`n",'/')}}
    
    
    }
    
    
    $report | Export-Csv -Path C:\result\extract.csv -NoTypeInformation -UseCulture
    

     

     

     

    thank you for your response



  • 2.  RE: Export list of vms with objet and createdtime

    Posted Nov 23, 2021 03:36 PM

    That should be CreateDate instead of CreatedTime afaik.

    Note that this property is only available since vSPhere 6.7 (VCSA and ESXi) and PowerCLI 10.1.0



  • 3.  RE: Export list of vms with objet and createdtime

    Posted Nov 29, 2021 08:47 AM

    This is a vsphere 6.5.0.37000 and a powercli 6.5 R1 version

    the script gives me the empty field, I have no error



  • 4.  RE: Export list of vms with objet and createdtime

    Posted Nov 29, 2021 10:54 AM

    Since you are on vSPhere 6.5, that property is not available (like I already stated in my previous reply, and which someone was so friendly to repeat).



  • 5.  RE: Export list of vms with objet and createdtime

    Posted Nov 23, 2021 03:40 PM

    Ciao

    What error/warning does the script report?
    What version of ESXi are you using? Only from version 6.7 is the value of creating the VM available.
    Otherwise, you have to search for the events .. if they have not already been deleted.