Browse VMware Datastores w/PowerCLi

Cover

Are you sure do you know what happens on your Datastores? Where your ISO images are stored? How many orphaned virtual disks do you have? What is their size and how old are they? What more ever consumes your expensive storage space?

The Search-Datastore function from my PowerCLi Vi-Module module will answer all these and many another questions.

Search-Datastore

  • The function accepts Datastore(s) by name or as objects, returned by Get-Datastore cmdlet at the pipeline.
Get-Datastore | Search-Datastore
Search-Datastore –Datastore datastore1

01.Search-Datastore_Default

  • If you pass a large bulk of Datastores to the function, I suggest using –VerboseDatastoreName parameter to watch for Datastores processing progress.
Get-Datastore | Search-Datastore -VerboseDatastoreName

02.Search-Datastore_VerboseDatastoreName

-FileType parameter

  • By default, the function searches for these two file types: VMDK and ISO.

You can change the default behavior of the function and return ISO files only by using –FileType parameter.

Get-Help Search-Datastore –Parameter FileType
Get-Datastore | Search-Datastore -FileType IsoOnly

03.Search-Datastore_IsoOnly

  • I suggest you always to save the output to a variable and after that manipulate with that variable (filter/query/sort/export/format).
$report = Get-Datastore | Search-Datastore
$report | sort SizeGB |ft Folder, File, SizeGB –au
$report | ? {$_.SizeGB –gt 3}
$report |epcsv –notype –Encoding utf8 .\Datastore.csv

04.Search-Datastore_IsoOnlyOutput

  • The –FileType parameter supports four values: Vmdk&Iso, VmdkOnly, IsoOnly and All.

05.Search-Datastore_VmdkOnly

SizeBar property

  • One of the interesting properties, returned by Search-Datastore is SizeBar. This property represents relative file size compared to its parent Datastore size.

06.Search-Datastore_VmdkOnlyOutput

  • The SizeBar property is being generated by New-PercentageBar function, included in the module.

-FileName parameter

  • The –FileName parameter accepts file name pattern. If your pattern does not include no one asterisk symbol (*), the function will add one leading and one trailing asterisk to your pattern.
Get-Datastore | Search-Datastore -FileType IsoOnly –FileName 2008
  • The pattern will be *2008*.

07.Search-Datastore_FileNameAsterisk

FileType property

  • The one more interesting property, returned by Search-Datastore is FileType. This property represents well known VM and ESXi host file types.

08.Search-Datastore_FileType

  • In the screenshot above we can see three Virtual Disks (*.vmdk files) that reside on the same Datastore and consume 80% of its size (6+30+44).

  • That is not all about FileType property. For the Virtual Disk and Snapshot Disk file types, the function is able to determine if these files are used by any VM!

  • If no, the function will add Orphaned to the FileType name.

09.Search-Datastore_FileTypeOrphaned

  • Note! For correct orphaned disks determining you must connect to all VCenters or ESXi hosts that have access to the Datastores where you are searching for the files.
  • For more details about the function, please take a look at the content based help and examples.

Get-Help Search-Datastore -Full
Get-Help Search-Datastore -Examples
Get-Help Search-Datastore -Parameter FileName

You may also like:

Move-Template2Datastore – Migrate VMware VM Templates to another Datastore

One thought on “Browse VMware Datastores w/PowerCLi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s