VMware Cloud Community
Gaprofittit
Contributor
Contributor
Jump to solution

Specify a datastore in scripts

Hi,

For this script how do I specify a particular datastore within that cluster?

#Get source template
$Template = Get-Template -Name 'template_1601422'
#Get a host within the development cluster
$VMHost = Get-Cluster 'Carrollton Dev - Vsphere 5' | Get-VMHost | Get-Random
#Deploy our New VM
New-VM -Template $Template -Name 'devtest1' -VMhost $VmHost

Thanks,

Greg

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can use a Where-clause to filter the one(s) you want.

Get-Cluster 'Carrollton Dev - Vsphere 5' | Get-VMHost | Get-Datastore | Where {$_.Name -eq "equallogic-1-vol-2"} | Sort-Object -Unique

But why make it so difficult, you can just do the Get-Datastore with that name.

Get-Datastore -Name "equallogic-1-vol-2"


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

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

Pass all the ESX(i) hosts in the cluster and then only keep the unique objects.

Get-Cluster 'Carrollton Dev - Vsphere 5' | Get-VMHost | Get-Datastore | Sort-Object -Unique


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

0 Kudos
Gaprofittit
Contributor
Contributor
Jump to solution

Excuse my lack of knowledge, i'm a complete noob with powercli, where do i put in that syntax say "equallogic-1-vol-2"

Thanks,

Greg

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can use a Where-clause to filter the one(s) you want.

Get-Cluster 'Carrollton Dev - Vsphere 5' | Get-VMHost | Get-Datastore | Where {$_.Name -eq "equallogic-1-vol-2"} | Sort-Object -Unique

But why make it so difficult, you can just do the Get-Datastore with that name.

Get-Datastore -Name "equallogic-1-vol-2"


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

0 Kudos
Gaprofittit
Contributor
Contributor
Jump to solution

Awesome, thanks for the help..

Greg

0 Kudos
vsmorfa
Contributor
Contributor
Jump to solution

Hi LucD.
I'm using a script to create a .csv file to monitor the latency of my datastores.
In this report I put the information I need in this way:

Foreach ($oEntry in $Report) {

$oObject = New-Object PSObject -Property @{


Entity = $oEntry.Entity

Instance = $oEntry.Instance

MetricId = $oEntry.MetricId

Timestamp = ($oentry.Timestamp).toString('dd/MM/yyyy HH:mm')

Value = $oEntry.Value

Unit = $oEntry.Unit

}

Now, I would like to know if there is a way to change the Instance = $oEntry.Instance, that returns something like that: 4d4b3f85-db8f3f4c-3fc4-984be1xxxxxx,  with the name of the datastore, I mean something like Datastore1, Datastore2 ecc. ecc.
Thank you

V.

0 Kudos