PowerCLI

 View Only
  • 1.  Get size of file in datastore from full path

    Posted Mar 03, 2010 12:31 PM

    Hi,

    I have the full path to a file in a datastore and I need to get the file size.

    I've seen that this can be done using datastore.SearchDatastoreSubFolders to search the parent folder but this seems like a difficult way to get the file size of a single file.

    Thanks for any help,

    Kev



  • 2.  RE: Get size of file in datastore from full path

    Posted Mar 03, 2010 01:43 PM

    You can use the vmstores drive. Like the next example. vito is the name of our vCenter server. 501 is the returned length.

    Z:\vmware\scripts> (dir "vmstores:\vito@443\VMware Infrastructure Test Omgeving\vito_vmfs02\scompxx64\scompxx64.vmdk").length

    501

    Z:\vmware\scripts> get-datastore | % { $_.datastorebrowserpath}

    vmstores:\vito@443\VMware Infrastructure Test Omgeving\vito_vmfs02

    vmstores:\vito@443\VMware Infrastructure Test Omgeving\vito_vmfs01

    vmstores:\vito@443\VMware Infrastructure Test Omgeving\vito_vmfs03

    vmstores:\vito@443\VMware Infrastructure Test Omgeving\scomp0407_boot (1)

    vmstores:\vito@443\VMware Infrastructure Test Omgeving\scomp0408_boot (1)

    vmstores:\vito@443\VMware Infrastructure Test Omgeving\vito_vmfs04_nfs

    Z:\vmware\scripts> dir "vmstores:\vito@443\VMware Infrastructure Test Omgeving\vito_vmfs02"

    Datastore path:

    LastWriteTime Type Length Name

    -


    -


    -


    -


    22-9-2009 10:47 Folder RDPtest

    11-3-2009 11:23 Folder vcomp000x

    28-7-2009 14:05 Folder templ_w2k3x64R2_tst

    28-7-2009 15:11 Folder proefkonijn

    21-9-2009 14:49 Folder templ_w2k3x64R2

    15-2-2010 11:38 Folder proefkonijn2

    1-10-2009 12:24 Folder scompxx64

    4-11-2009 13:45 Folder scomp0065tst



  • 3.  RE: Get size of file in datastore from full path

    Posted Mar 03, 2010 01:47 PM

    You also use the datastore provider that comes with PowerCLI.

    Something like this

    $datastore = "dsName"
    $path = "Folder\filename.filetype"
    
    ls ((Get-Datastore -Name $datastore).DatastoreBrowserPath + "\" + $path)
    

    Where Folder is normally the name of the guest.

    For example for a guest named PC1 on datastore DS1 where you want to see the size of the VMDK file this would become

    $datastore = "DS1"
    $path = "PC1\PC1.vmdk"
    
    ls ((Get-Datastore -Name $datastore).DatastoreBrowserPath + "\" + $path)
    

    The length property will contain the size of the file.

    Note that the datastore provider is not too fast and it's not 100% production ready yet.

    ____________

    Blog: LucD notes

    Twitter: lucd22