leoiossi
Contributor
Contributor

Shared Vmdks Between Vms - How can display this info by script

I need to know how many Vms has shared disks, wich are hostnames and clusters. Have an script for that or cmdlets ?????

0 Kudos
4 Replies
LucD
Leadership
Leadership

Try something like this

foreach($vm in Get-VM){
   
$sharedSC= Get-ScsiController -VM $vm |
       
where {"Virtual","Physical" -contains $_.BusSharingMode}
   
if($sharedSC){
       
$sharedSCKey = $sharedSC | %{$_.Key}
       
Get-HardDisk -VM $vm |
           
where {$sharedSCKey -contains $_.ExtensionData.ControllerKey} |
       
Select @{N="VM";E={$_.Parent.Name}},Name,Filename
    }
}


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

0 Kudos
bikashyadav
Contributor
Contributor

Hi LucD,

How do i import it to a excel or csv ?

Thanks

Bikash

0 Kudos
LucD
Leadership
Leadership

The foreach doesn't place anything on the pipeline.

But you can fix this issue by running it as a codeblock.

&{foreach($vm in Get-VM){

    $sharedSC= Get-ScsiController -VM $vm |

        where {"Virtual","Physical" -contains $_.BusSharingMode}

    if($sharedSC){

        $sharedSCKey = $sharedSC | %{$_.Key}

        Get-HardDisk -VM $vm |

            where {$sharedSCKey -contains $_.ExtensionData.ControllerKey} |

        Select @{N="VM";E={$_.Parent.Name}},Name,Filename

    }

}} |

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

0 Kudos
bikashyadav
Contributor
Contributor

Thank you LucD. I will try.

0 Kudos