Hi All,
I'm new to these forums and to PowerCLI. I'm trying to do something that I thought would be straight forward but I'm failing miserably.
I want to create a script that will take a list of specific datastores and output each specified datastore and the VMs that are on it.
Example Output:
Datastore VM
-------------- ----------------
Datastore1 VM1
Datastore1 VM2
Datastore2 VM3
Datastore2 VM4
Example of a script that I've tried to create:
$Result=@()
$Datastores=Get-Datastore <Datastore1>,<Datastore2>
foreach ($Datastore in $Datastores)
{
$Result+=Get-datastore $Datastore | Get-VM | select @{N="Datastore";E={$Datastore.Name}},@{N="VM";E={$VM.Name}}
}
$Result
This is just one of many examples of scripts that I've tried and failed with. Any help is VERY appreciated. Thanks in advance!
One way of doing that is like this
foreach($ds in Get-Datastore -Name datastore1,datastore2){
Get-VM -Datastore $ds |
Select Name,@{N="Datastore";E={$ds.Name}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
One way of doing that is like this
foreach($ds in Get-Datastore -Name datastore1,datastore2){
Get-VM -Datastore $ds |
Select Name,@{N="Datastore";E={$ds.Name}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks! This worked like a charm!