VMware Cloud Community
halr9000
Commander
Commander
Jump to solution

Get-Datastore can't handle wildcards very well

Check this out. Note that I don't have a VMhost named bob.

PS > Get-Datastore -VMHost bob
Get-Datastore : 8/2/2008 5:32:52 PM    Get-Datastore        Could not find VMHost with name 'bob'.
At line:1 char:14
+ Get-Datastore <<<<  -VMHost bob
Get-Datastore : Could not find all of the objects specified by name.
At line:1 char:14
+ Get-Datastore <<<<  -VMHost bob
PS > Get-Datastore -VMHost bob*

Name                               FreeSpaceMB      CapacityMB
----                               -----------      ----------
SCSI_ESX1_VOL1                           11609           26880
SCSI_ESX2_VOL1                            2552           26880
SCSI_ESX1_VOL2                           69327           69888
ISCSI_OPENFILER                           3436            3840

I tested this with the VM parameter and also got the same "liberal interpretation" of the wildcard. Conversely, "get-vm -name foo*" does not list all of my VMs (as I would expect).

Please fix this...it's the sort of thing that is going to really mess up a script.

Author of the upcoming book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

Thank you for clarifying this to me Hugo. I confirmin this case this is a bug that will be fixed in future release. Will log it into database

Thank you Hal and Hugo for pointing that.

View solution in original post

0 Kudos
6 Replies
halr9000
Commander
Commander
Jump to solution

I'm finding also that other filters which fail will result in the returning of every datastore. For example, take this invalid search on Entity:

PS > Get-Datastore -Entity ( Get-VM fudgeapp01 | Get-Snapshot )
WARNING: 'Entity' parameter only accepts objects of type VirtualMachine, VMHost, and
Datacenter. Skipping a parameter of type 'SnapshotImpl'.)
WARNING: 'Entity' parameter only accepts objects of type VirtualMachine, VMHost, and
Datacenter. Skipping a parameter of type 'SnapshotImpl'.)

Name                               FreeSpaceMB      CapacityMB
----                               -----------      ----------
SCSI_ESX1_VOL1                           11609           26880
SCSI_ESX2_VOL1                            2552           26880
SCSI_ESX1_VOL2                           69327           69888
ISCSI_OPENFILER                           3436            3840

P.S. Seems to me the entity param is 100% redundant, as there are params for each of the types mentioned in the warning message. Is that the case (and it will be removed in a future build), or am I missing something?

Author of the upcoming book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
admin
Immortal
Immortal
Jump to solution

Hi Hal,

The first example '

PS > Get-Datastore -VMHost bob

' fails because your host name is probably hal.mydomain.com. The second example passes because bob* will match the whole name. To check if this is correct just run 'Get-VMHost bob'

As for your second example 'Get-Datastore -Entity ( Get-VM fudgeapp01 | Get-Snapshot )' will get the datastore where the VM fudgeapp01 is. The Warning you see is because snapshot is not a valid entity object for Get-Datastore. That is the reason you get Warning and result.

Regards,

Georgi Rusev

0 Kudos
hugopeeters
Hot Shot
Hot Shot
Jump to solution

I think what Hal means is this:

1. Instead of returning no datastores because there is no VMHost that matches bob*, the cmdlet returns ALL datastores (as if the filter was *).

2. He knows the argument is invalid. But áfter getting back an error, the cmdlet returns ALL datastores (as if no argument was supplied at all).

This is very risky behaviour for a cmdlet!

admin
Immortal
Immortal
Jump to solution

Thank you for clarifying this to me Hugo. I confirmin this case this is a bug that will be fixed in future release. Will log it into database

Thank you Hal and Hugo for pointing that.

0 Kudos
admin
Immortal
Immortal
Jump to solution

For now you can workarround this problem if you use this notation:

get-vmhost bob* | Get-datastore

halr9000
Commander
Commander
Jump to solution

Thanks Hugo for elaborating and thanks Georgi for tracking the bug.

Author of the upcoming book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos