I am trying to figure out how to write a script that will result in 2 columns, Name and Datastore. The Name column would contain the VM Name and the Datastore would be the normal datastore name. I am new to PowerCLI and just getting frustrated trying to figure this out on my own. Please help.
Try it like this
foreach($vm in Get-VM){
Get-Datastore -vm $vm | Select @{N="VM";E={$vm.Name}},Name
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try it like this
foreach($vm in Get-VM){
Get-Datastore -vm $vm | Select @{N="VM";E={$vm.Name}},Name
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc. I appreciate it.
LucD,
If want to export in CSV format these output.Please help me on
foreach($vm in Get-VM){
Get-Datastore -vm $vm | Select @{N="VM";E={$vm.Name}},Name
} Export-Csv "C:\VM_Datastore.csv" -NoTypeInformation -UseCulture
It shows error
That's because the Foreach-Object cmdlet doesn't place anything in the pipeline.
A way around this, is to capture the output in a variable and export that one to a CSV file.
Something like this
$report = foreach($vm in Get-VM){
Get-Datastore -vm $vm | Select @{N="VM";E={$vm.Name}},Name
}
$report | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD I appreciate You.
Thanks for the tips. I scrateched my head to bring it into the export-csv.
Let's say I want to be able to click on a VM from the results and vMotion it over with an Action in PowerGUI, and lets say the action script is what is listed below...Why would I receive the error "Move-VM Invalid / explicitly disabled state operation is invoked. (Move-VM)
$input | ForEach-Object {
$Dest = Read-Host "Where the Heck do you want it now???"
Move-VM -VM $_.Name -Destination $Dest
}
Interestingly enough, I was testing this in our LabManager environment and was receiving the error, but when I run in a Non-LM environment it works like a dream.
I suspect this is due to the fact that Lab Manager is using so-called linked clones.
And afaik you can't do a Move-VM on these.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference