Automation

 View Only
  • 1.  Find all hosts which share disks using various methods

    Posted May 24, 2022 06:21 PM

    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?



  • 2.  RE: Find all hosts which share disks using various methods
    Best Answer

    Posted May 24, 2022 06:38 PM

    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).

    Combined that could be something like this



  • 3.  RE: Find all hosts which share disks using various methods

    Posted May 24, 2022 08:15 PM

    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?



  • 4.  RE: Find all hosts which share disks using various methods

    Posted May 24, 2022 09:08 PM

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



  • 5.  RE: Find all hosts which share disks using various methods

    Posted May 25, 2022 12:34 PM

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



  • 6.  RE: Find all hosts which share disks using various methods

    Posted May 25, 2022 12:46 PM

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