VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

hash_table and splatting

Hi Luc,

good evening ,

if you could suggest  on the following two scenarios.

orange code is using hash table .

green code is for splatting to check simple command .is this the correct way of using splatting??

$esxi_count=(get-vmhost).count

$vm_count=(get-vm).count

$vcenter=$global:DefaultVIServer

$Result = New-Object PSObject -Property @{

        esxicount = $esxi_count;

        vmcount = $vm_count;

      

        #version_applaince = $version_appliance

        vcenter=$global:DefaultVIServer

    }

    $result

   #using splatting

    $esxi_info = @{

   

    location = "cluster1"

    datastore = "datastore1"

    }

    get-vmhost @esxi_info

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Yes, splatting uses a hash table to define the parameter and their values for a cmdlet.
You then call the cmdlet, and pass the hash table with the @ character.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
8 Replies
Gidrakos
Hot Shot
Hot Shot
Jump to solution

I'm not Luc but I can confirm that's correct splatting Smiley Happy

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, splatting uses a hash table to define the parameter and their values for a cmdlet.
You then call the cmdlet, and pass the hash table with the @ character.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks  Luc is green code working for you .i thought of using it on simple command however i am not getting any output for that.

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaks.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, it is.
Provided of course there are ESXi nodes in that cluster and that are associated to that datastore.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks  it is working .

one extra thing i want to know if you

can you please suggest the most stable powercli version as of today to be updated to .

0 Kudos
LucD
Leadership
Leadership
Jump to solution

In theory, the latest version is always the greatest.
That is currently 11.5.0, see New Release – PowerCLI 11.5.0


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thanks.

0 Kudos