VMware Cloud Community
sivagndl
Enthusiast
Enthusiast

Need help Datastore details

Hi Friends,

I need Scrip for getting Datastore name ,total storage and path(MMR,Round Robin, fixed)..

Pls hep me Fnd's

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership

Try something like this

Get-Datastore  | 
Select Name,CapacityMB,
  @{N="PathType";E={     Get-ScsiLun -Datastore $_ | Select -First 1 | Select -ExpandProperty MultiPathPolicy
  }}

If you have different pathing policies on different hosts for shared datastores, then this script will not show that.


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

Reply
0 Kudos
sivagndl
Enthusiast
Enthusiast

We have multiple storeges and multiple hosts.

We need to find out the Data store path policy on each and every host. also we need to change the policy from fixed to Roundrobbin

Kindly provide me the script.

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

You can get the multipathpolicy for every lun on every host with:

Get-VMHost |
Get-ScsiLun |
Where-Object {$_.LunType -eq "Disk"} |
Select-Object -Property VMHost,CanonicalName,MultipathPolicy

And you can set the multipathpolicy to RoundRobin for all the luns with:

Get-VMHost |
Get-ScsiLun |
Where-Object {$_.LunType -eq "Disk" -and $_.MultipathPolicy -ne "RoundRobin"} |
Set-ScsiLun -MultipathPolicy RoundRobin

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
LucD
Leadership
Leadership

Since you seem to have asked for this on a datastore basis, you can use the following

foreach($esx in Get-VMHost  ){
  Get-Datastore -VMHost $esx | 
  Select @{N="Host";E={$esx.Name}},Name,CapacityMB,
 
@{N="PathType";E={       Get-ScsiLun -Datastore $_ | Select -First 1 | Select -ExpandProperty MultiPathPolicy
    }} }

And to change the Fixed paths to RoundRobin you can do

foreach($esx in Get-VMHost){
  Get-Datastore -VMHost $esx | %{
    Get-ScsiLun -Datastore $_ |  
    where {$_.MultiPathPolicy -eq "Fixed"} |
   
Set-ScsiLun -MultipathPolicy RoundRobin -Confirm:$false
  } }

Doing this starting from the datastores avoids that you change the pathing policy for RDM and other non-datastore LUNs.


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

Reply
0 Kudos
sivagndl
Enthusiast
Enthusiast

Thanks for the info. also let me know to get the host IP address and DataStore Name also.

here using the given script i am getting the Host ID and datastore Naa ID.

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

The next script will give you the host name, all the IP addresses assigned to the host, the datastore name and the multipath policy:

Get-VMHost |
ForEach-Object {
  $VMHost = $_
  $VMHost | Get-Datastore |
  ForEach-Object {
    $Datastore = $_
    $Datastore | Get-ScsiLun |
    Select-Object -Property VMHost,@{
        Name="IP"
        Expression={[string]::Join(',',($VMHost |
          Get-VMHostNetworkAdapter |
          Where-Object {$_.IP} |
          ForEach-Object {$_.IP}))}},
      @{Name="Datastore";Expression={$Datastore.Name}},MultipathPolicy
  }
}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
sivagndl
Enthusiast
Enthusiast

We are getting the following error while executing the script.

Unexpected token 'VMHost' in expression or statement.
At line:1 char:46
+ Get-VMHost |ForEach-Object {$VMHost=$_$VMHost <<<<  |Get-Datastore |ForEach-O
bject{$Datastore=$_$Datastore |Get-ScsiLun |Select-Object -Property VMHost,@{Na
me="IP" Expression={[String]::Join(',',($VMHost |Get-VMHostNetworkAdapter |Wher
e-Object {$_.IP} |ForEach-Object {$_.IP}))}},@{Name="Datastore";Expression={$Da
tastore.Name}},Multipathpolicy}}
    + CategoryInfo          : ParserError: (VMHost:String) [], ParentContainsE
   rrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

There must have gone something wrong with cutting and pasting the script. It looks like two lines are appended. This is a known problem with Internet Explorer and the forum software. You might try another browser. Or make sure that every line of the script in my example, is on a different line on your computer as well.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos