VMware Cloud Community
dbutch1976
Hot Shot
Hot Shot
Jump to solution

Find all hosts which share disks using various methods

Hello,

I have this script to find VMs using shared disks:
"_________________________________________________________________________"
"The VMs below have shared disks and reside on hosts which must be patched. Must be scheduled."
Get-VM -PipelineVariable vm | Get-ScsiController | Where-Object {$_.BusSharingMode -in 'Virtual','Physical'} | Select Parent,BusSharingMode,@{N='VMHost';E={$vm.VMHost.Name}},@{N='Version';E={$vm.VMHost.version}} | Out-Default
"

However I now realize that many VMs actually share disks by setting the actual disk to mult-writer rather than via the SCSI controller. Is there an easy way to re-write this script so that it finds shared disk regardless of how which method they're using?

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

It is probably a lot easier to do that in a separate line of code, but keep the same output properties (although BusSharingMode is technically not correct for disks marked as MultiWriter).

Get-VM -PipelineVariable vm |
Get-HardDisk |
Where-Object {$_.ExtensionData.Backing.Sharing -ne 'sharingNone'} |
Select Parent, @{N='BusSharingMode';E={'MultiWriter'}},
  @{N = 'VMHost'; E = { $vm.VMHost.Name } },
  @{N = 'Version'; E = { $vm.VMHost.version } }

Combined that could be something like this

Get-VM -PipelineVariable vm |
ForEach-Object -Process {
  Get-ScsiController -VM $vm |
  Where-Object { $_.BusSharingMode -in 'Virtual', 'Physical' } |
  Select-Object Parent, BusSharingMode,
    @{N = 'VMHost'; E = { $vm.VMHost.Name } },
    @{N = 'Version'; E = { $vm.VMHost.version } }

  Get-HardDisk -VM $vm |
  Where-Object {$_.ExtensionData.Backing.Sharing -ne 'sharingNone'} |
  Select Parent, @{N='BusSharingMode';E={'MultiWriter'}},
    @{N = 'VMHost'; E = { $vm.VMHost.Name } },
    @{N = 'Version'; E = { $vm.VMHost.version } }
} | Out-Default


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

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

It is probably a lot easier to do that in a separate line of code, but keep the same output properties (although BusSharingMode is technically not correct for disks marked as MultiWriter).

Get-VM -PipelineVariable vm |
Get-HardDisk |
Where-Object {$_.ExtensionData.Backing.Sharing -ne 'sharingNone'} |
Select Parent, @{N='BusSharingMode';E={'MultiWriter'}},
  @{N = 'VMHost'; E = { $vm.VMHost.Name } },
  @{N = 'Version'; E = { $vm.VMHost.version } }

Combined that could be something like this

Get-VM -PipelineVariable vm |
ForEach-Object -Process {
  Get-ScsiController -VM $vm |
  Where-Object { $_.BusSharingMode -in 'Virtual', 'Physical' } |
  Select-Object Parent, BusSharingMode,
    @{N = 'VMHost'; E = { $vm.VMHost.Name } },
    @{N = 'Version'; E = { $vm.VMHost.version } }

  Get-HardDisk -VM $vm |
  Where-Object {$_.ExtensionData.Backing.Sharing -ne 'sharingNone'} |
  Select Parent, @{N='BusSharingMode';E={'MultiWriter'}},
    @{N = 'VMHost'; E = { $vm.VMHost.Name } },
    @{N = 'Version'; E = { $vm.VMHost.version } }
} | Out-Default


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

Reply
0 Kudos
dbutch1976
Hot Shot
Hot Shot
Jump to solution

I added a little bit to make it a little more specific to my purpose - I want to identify all hosts which need to be upgraded however contain VMs which cannot be motioned, like shared-disks. For some reason if I try to add the "folder" field nothing comes out:

 

$cluhosts = get-vmhost | Where-Object {$_.version -notmatch "7.0.3" -and $_.parent -notmatch "xyz" -and $_.Name -notmatch "xyz"}
foreach ($cluhost in $cluhosts) {

get-vmhost -Name $cluhost | Get-VM -PipelineVariable vm |
ForEach-Object -Process {
Get-ScsiController -VM $vm |
Where-Object { $_.BusSharingMode -in 'Virtual', 'Physical' } |
Select-Object Parent, Folder, BusSharingMode,
@{N = 'VMHost'; E = { $vm.VMHost.Name } },
@{N = 'Version'; E = { $vm.VMHost.version } }

Get-HardDisk -VM $vm |
Where-Object {$_.ExtensionData.Backing.Sharing -ne 'sharingNone'} |
Select Parent, Folder, @{N='BusSharingMode';E={'MultiWriter'}},
@{N = 'VMHost'; E = { $vm.VMHost.Name } },
@{N = 'Version'; E = { $vm.VMHost.version } }
}| Out-Default

}

 

Any ideas?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Instead of Folder use the calculated property (the object in the pipeline is not a VM)

Select-Object ..., @{N='Folder';E={$vm.Folder.Name}}, ...


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

Reply
0 Kudos
dbutch1976
Hot Shot
Hot Shot
Jump to solution

Thanks LucD! Can I export all this to csv without losing the formating?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, add a pipeline symbol followed by Export-Csv after the last curly brace


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