VMware Cloud Community
Narayanan_5245
Enthusiast
Enthusiast
Jump to solution

Script to get Virtual machine RDM SCSI Controller & Bus Sharing Mode Report

Hi Team,

Can anyone please help to suggest if we can have a script to pull the VM RDM SCSI Controller & Bus Sharing Mode along with host and cluster from the vCenter.

Thank you

Regards

Narayanan.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do

Get-Cluster -PipelineVariable cluster |

Get-VMHost -PipelineVariable esx  |

Get-VM -PipelineVariable vm |

Get-HardDisk -DiskType RawPhysical,RawVirtual |

Select @{N='Cluster';E={$cluster.Name}},

    @{N='VMHost';E={$esx.Name}},

    @{N='VM';E={$vm.Name}},

    Name,

    @{N='HDSharingMode';E={$_.ExtensionData.Backing.Sharing}},

    @{N='Controller';E={

        $script:ctrl = Get-ScsiController -HardDisk $_

        $script:ctrl.Name  

    }},

    @{N='CtrlType';E={$script:ctrl.Type}},

    @{N='CtrlBusSharing';E={$script:ctrl.BusSharingMode}}


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

View solution in original post

21 Replies
LucD
Leadership
Leadership
Jump to solution

Yes, you can.


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast
Jump to solution

Hi LuCD,

Used the below which you already suggested in other thread, but couldn't get the controller & sharing mode of the RDM disks. Can you help.

Get-VM | Get-HardDisk |

where {"RawPhysical","RawVirtual" -contains $_.DiskType -and

       "Physical","Virtual" -contains (Get-ScsiController -HardDisk $_).BusSharingMode} |

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

    Name,

    FileName,

    CapacityGB,

    DiskType,

    ScsiCanonicalName,

    @{N='BusSharing';E={(Get-ScsiController -HardDisk $_).BusSharingMode}}

Regards

Narayanan.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do

Get-Cluster -PipelineVariable cluster |

Get-VMHost -PipelineVariable esx  |

Get-VM -PipelineVariable vm |

Get-HardDisk -DiskType RawPhysical,RawVirtual |

Select @{N='Cluster';E={$cluster.Name}},

    @{N='VMHost';E={$esx.Name}},

    @{N='VM';E={$vm.Name}},

    Name,

    @{N='HDSharingMode';E={$_.ExtensionData.Backing.Sharing}},

    @{N='Controller';E={

        $script:ctrl = Get-ScsiController -HardDisk $_

        $script:ctrl.Name  

    }},

    @{N='CtrlType';E={$script:ctrl.Type}},

    @{N='CtrlBusSharing';E={$script:ctrl.BusSharingMode}}


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

Narayanan_5245
Enthusiast
Enthusiast
Jump to solution

Works Perfectly LuCD. Great.

One additional request, Is it possible to include the HD Disk Compatibility mode (Physical) & Virtual device node (1:5) number along with this report as well.

pastedImage_4.png

Regards

Narayanan.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Cluster -PipelineVariable cluster |

Get-VMHost -PipelineVariable esx  |

Get-VM -PipelineVariable vm |

Get-HardDisk -DiskType RawPhysical,RawVirtual |

Select @{N='Cluster';E={$cluster.Name}},

    @{N='VMHost';E={$esx.Name}},

    @{N='VM';E={$vm.Name}},

    Name,DiskType,

    @{N='HDSharingMode';E={$_.ExtensionData.Backing.Sharing}},

    @{N='Controller';E={

        $script:ctrl = Get-ScsiController -HardDisk $_

        $script:ctrl.Name

    }},

    @{N='vDevNode';E={

        "{0}:{1}" -f $script:ctrl.ExtensionData.BusNumber,$_.ExtensionData.UnitNumber

    }},

    @{N='CtrlType';E={$script:ctrl.Type}},

    @{N='CtrlBusSharing';E={$script:ctrl.BusSharingMode}}


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

Narayanan_5245
Enthusiast
Enthusiast
Jump to solution

Got the expected Output and made it very easy. Thank you for your support LuCD. Genius!!.

One last request, if this possible can we able to run this script on 2 Center servers (different credentials) simultaneously and make it to single report.

I have tried to ran Connect-VI server vCenter1, vCenter2 but the last one only taking for the consideration and pulling a report for the second vCenter server.

Set-PowerCli configuration to Multiple mode & All users, session as well, no luck. Please advise.

Regards

Narayanan.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you check you actually have 2 connections open?
What is in $global:defaultVIServers?


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast
Jump to solution

seems the first session getting overridden while connecting the second vCenter server. Please find below the output

Windows PowerShell

Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator> Connect-VIServer vCenter1.vsphere.local,vCenter2.dev.local

Name                                          Port  User

----                                               ----  ----

vCenter1.vsphere.local              443   root

vCenter2.dev.local                     443   root

PS C:\Users\Administrator> $global:defaultVIServers

Name                                          Port  User

----                                               ----  ----

vCenter2.dev.local                      443   root

Regards

Narayanan

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then it looks as if the DefaultViServer mode is still set to 'Single'.
Check with Get-PowerCLIConfiguration, and eventually change with Set-PowerCLIConfiguration.

Note that these settings have different scopes.


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast
Jump to solution

Set the mode to Multiple but got the only output of one vCenter server other throws error.

PowerCLI C:\compaq> $global:defaultVIServers

Name                                   Port  User

----                                          ----  ----

vCenter1.vsphere.local         443   root

vCenter2.dev.local                443   root

PowerCLI C:\compaq> .\RDMLUN8.ps1

Get-VM : 9/29/2020 1:59:18 PM   Get-VM          Exception has been thrown by the target of an invocation.

At C:\compaq\RDMLUN8.ps1:4 char:1

+ Get-VM -PipelineVariable vm |

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

PowerCLI C:\compaq> Get-PowerCLIConfiguration

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout

                                                                                                  Seconds

-----    -----------     ------------------- ------------------------  -------------------------- -------------------

Session  UseSystemProxy  Multiple            Unset                     True                       300

User                                     Multiple

AllUsers

Regards

Narayanan

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you get the same error when you do a simple Get-VM from the PS prompt?


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast
Jump to solution

Hi LuCD,

Tried with other 2 vCenter servers that have VMs with RDMs and could get the report of both vCenter reports.

Maybe earlier it's not reported due to one of the vCenter doesn't have any VMs attached with RDMs.

But curious to understand the below error while running the script for multiple vCenter servers.

PowerCLI C:\compaq> .\RDMLUN8.ps1

Get-VM : 9/29/2020 4:28:08 PM   Get-VM          Exception has been thrown by the target of an invocation.

At C:\compaq\RDMLUN8.ps1:4 char:1

+ Get-VM -PipelineVariable vm |

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : 9/29/2020 4:28:14 PM   Get-VM          Exception has been thrown by the target of an invocation.

At C:\compaq\RDMLUN8.ps1:4 char:1

+ Get-VM -PipelineVariable vm |

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Script

Get-Cluster -PipelineVariable cluster |

Get-VMHost -PipelineVariable esx  |

Get-VM -PipelineVariable vm |

Get-HardDisk -DiskType RawPhysical,RawVirtual |

Select @{N='VM';E={$vm.Name}},

    @{N='Cluster';E={$cluster.Name}},

    @{N='VMHost';E={$esx.Name}},

    Name,DiskType,

    @{N='HDSharingMode';E={$_.ExtensionData.Backing.Sharing}},

    @{N='Controller';E={

        $script:ctrl = Get-ScsiController -HardDisk $_

        $script:ctrl.Name

    }},

    @{N='CtrlType';E={$script:ctrl.Type}},

    @{N='CtrlBusSharing';E={$script:ctrl.BusSharingMode}},

    @{N='vDevNode';E={

        "{0}:{1}" -f $script:ctrl.ExtensionData.BusNumber,$_.ExtensionData.UnitNumber

    }} | Export-csv -Path "C:\compaq\RDMReport_$(Get-Date -Format 'ddMMMyyyy').csv"

Regards

Narayanan

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No clue why that happened on that specific vCenter.
Did you try the Get-VM on that vCenter I asked earlier?


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast
Jump to solution

yes LuCD. Get-VM works fine and able to get both vCenter vms without any error.

Regards

Narayanan.

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast
Jump to solution

if I try to run the script, getting the output details but getting "Exception has been thrown by the target of an invocation".

Regards

Narayanan.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

And does this work in both vCenters?

Get-VM | Get-HardDisk -DiskType RawPhysical, RawVirtual


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast
Jump to solution

yes LuCD. Get-VM | Get-HardDisk -DiskType RawPhysical, RawVirtual command works fine and getting the output of both the vCenter virtual machines with RDM attached.

PowerCLI C:\compaq> .\RDMLUN6.ps1

Get-VM : 9/30/2020 5:14:32 PM   Get-VM          Exception has been thrown by the target of an invocation.

At C:\compaq\RDMLUN6.ps1:4 char:1

+ Get-VM -PipelineVariable vm |

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : 9/30/2020 5:14:51 PM   Get-VM          Exception has been thrown by the target of an invocation.

At C:\compaq\RDMLUN6.ps1:4 char:1

+ Get-VM -PipelineVariable vm |

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Regards

Narayanan

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then I have no clue why that error is happening on one of your vCenters


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast
Jump to solution

LuCD,

Thanks for checking and all the help.

Just realized the error is getting throwing is due to PowerCLI version VMware PowerCLI 6.5 Release 1 build 4624819. The same script tried in the latest version (VMware PowerCLI 10.1.0 build 8346946) and works without any errors.

Regards

Narayanan.

0 Kudos