VMware Cloud Community
tmancini
Contributor
Contributor
Jump to solution

Power CLI equivalent to esxcfg-volume -M

Need to force-mount all available volumes to a few ESXi 4.1 servers and hoping to accomplish this with PowerCLI.

Novice with PowerCLI but hoping there is something that can be used to automate force-mounting volumes.

Thanks.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The first Connect-VIServer should be to your vCenter, otherwise the Get-VMHost will not return all the hosts in the cluster.

And make sure that the VIServer mode is set to Multiple, that way you can have a connection to the server together with a connection to the ESXi server you're scanning.

Use the Set-PowerCLIConfiguration cmdlet for setting the mode.


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Have a look at the Powershell ResolveMultipleUnresolvedVmfsVolumes (equivalent of esxcfg-volume.pl) thread.

As Vitali remarked, you should do this while connected (Connect-VIServer) to the ESX(i) server and not the vCenter server.

And also have a look at the Enable Mount and resignature of  snap luns on vSphere thread


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

0 Kudos
tmancini
Contributor
Contributor
Jump to solution

Thanks, LucD.

The first one you linked to seems work well. Is there a way to have it call multiple ESXi servers and maybe prompt for credentials?

If I exclude the username and password and leave the variable references it will prompt and still works which is fine.

Here's what I've modified to get working;

#$cluster =
#$vcenter =
$user =
$password =
Connect-VIServer myESXiServer
Foreach($esxhost in (Get-VMHost -Location $cluster)){
    Connect-VIServer $esxhost -User $user -Password $password
    $hostView = get-vmhost -name $esxhost | get-view
    $dsView = get-view $hostView.ConfigManager.DatastoreSystem
    $unBound = $dsView.QueryUnresolvedVmfsVolumes()

    foreach ($ub in $UnBound) {
        $extPaths = @()
        $Extents = $ub.Extent;
        foreach ($ex in $Extents) {
        $extPaths = $extPaths + $ex.DevicePath
                                  }      
        $resolutionSpec = New-Object VMware.Vim.HostUnresolvedVmfsResolutionSpec[] (1)
        $resolutionSpec[0] = New-Object VMware.Vim.HostUnresolvedVmfsResolutionSpec
        $resolutionSpec[0].extentDevicePath = New-Object System.String[] (1)
        $resolutionSpec[0].extentDevicePath[0] = $extPaths
        $resolutionSpec[0].uuidResolution = "forceMount"

    $dsView = Get-View -Id 'HostStorageSystem-storageSystem'
    $dsView.ResolveMultipleUnresolvedVmfsVolumes($resolutionSpec)
    }
}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The first Connect-VIServer should be to your vCenter, otherwise the Get-VMHost will not return all the hosts in the cluster.

And make sure that the VIServer mode is set to Multiple, that way you can have a connection to the server together with a connection to the ESXi server you're scanning.

Use the Set-PowerCLIConfiguration cmdlet for setting the mode.


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

0 Kudos
tmancini
Contributor
Contributor
Jump to solution

Thanks, Luc.

I'll give it a go!

Thanks again for the info, much appreciated.

0 Kudos