VMware Cloud Community
Sureshadmin
Contributor
Contributor
Jump to solution

Need powershell scripts to collect ESX storage info

Hi,

I need three scripts to collect ESX storage information as given below

1. Storage hardware info --> to collect info about SCSI controller and HBA cards.

ESX Name | SCSI controller | HBA1 | HBA2

Expected output

ESX Name | SCSI (Model,Bios version,serial Number, Raid config) | HBA1(Model, Firmware version, serial number,WWPN) | HBA2(Model, Firmware version, serial number,WWPN)

Note : Need info about all SCSI controllers and HBA's in the ESX box, so additional columns could be added as required.

2.Storage usage report ---> Storage usage report including local filesystem storage and also SAN volumes.

ESX name | Filesystem | Size | Used | Avail | Use% | Mount Point | Extents

Note : Need all sizes in GB. Extents are applicable for SAN datastores and just need the extent DiskID like vmhba1:1:1

3. San disk information -->To collect information about San Disk

Disk ID | Lun ID | Disk Size | Make/Model | Path(s) | Policy | Active HBA WWPN

Expected Output

vmhba1:1:1 | 0110 | 130G | EMCxxxx | 4 | Fixed | xxxxxxxxxxxxxxx

0 Kudos
42 Replies
Sureshadmin
Contributor
Contributor
Jump to solution

hi Luc,

I have posted a script requirement in http://communities.vmware.com/thread/266556

Can you please check it and provide a script.

0 Kudos
wolficool
Contributor
Contributor
Jump to solution

Hi LucD,

how can i put the output into html table?

thx

0 Kudos
LucD
Leadership
Leadership
Jump to solution

For a simple HTML page you can use the ConvertTo-Html cmdlet.

If you want to go for a fancy HTML page you have multiple options.

See for example Creating Formatted HTML Output.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

When i run this this script, i don't see any result or i dont get any error. Simply it runs but does not show up any results. Can you please have a look? Looks like it needs your touch Smiley Wink

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Could this be caused by a missing host key fingerprint ?

Can you try a plink to the server from the DOS command prompt ?

Or is the account you are using not authorised to use SSH ?

Try the plink with the account you specified in the script.


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

0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

The account has ssh permission, i can connect via putty also the system has the fingerprint. Unfortunately currently could not test it with plink. Will test it soon.

Can you please help with this below piece of code, so that only 10 reconfigure tasks run at a time and not more than that. As the current running tasks completes the new tasks should initiate, but only 10 reconfigure tasks at a time.

get-cluster <clu-name> | get-vm | %{Get-View $_.ID} | %{
  $spec = new-object VMware.Vim.VirtualMachineConfigSpec;
  $spec.cpuAllocation = New-Object VMware.Vim.ResourceAllocationInfo;
  $spec.cpuAllocation.Shares = New-Object VMware.Vim.SharesInfo;
  $spec.cpuAllocation.Shares.Level = "Normal";
  $spec.cpuAllocation.Limit = -1;
  $spec.cpuAllocation.Reservation = 0;
   Get-View($_.ReconfigVM_Task($spec));
  }

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

$nrMax = 10 
$taskHash
= @{}

Get-Cluster <clu-name> | Get-VM | %{
 
$spec = new-object VMware.Vim.VirtualMachineConfigSpec;
 
$spec.cpuAllocation = New-Object VMware.Vim.ResourceAllocationInfo;
 
$spec.cpuAllocation.Shares = New-Object VMware.Vim.SharesInfo;
 
$spec.cpuAllocation.Shares.Level = "Normal";
 
$spec.cpuAllocation.Limit = -1;
 
$spec.cpuAllocation.Reservation = 0;
 
$task = Get-View ($_.Extensiondata.ReconfigVM_Task($spec))
 
$taskHash[$task.Info.Key] = $task

 
while($taskHash.Count -eq $nrMax){
   
foreach($task in $taskHash.Values){
       
$task.UpdateViewData()
       
if("success","error" -contains $task.Info.State){
           
$taskHash.Remove($task.Info.Key)
        }
    }
  }
}


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

0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

It gives out a error given below,

Method invocation failed because [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl] doesn't contain a method named 'ReconfigVM_Task'.

At :line:12 char:48

+ $task = Get-View (Get-View ($_.ReconfigVM_Task <<<< ($spec)))

0 Kudos
LucD
Leadership
Leadership
Jump to solution

My mistake, I corrected the typo.


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

0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Hi Luc,

It reconfigures one machine in the cluster and then gives out the error,

Cannot bind parameter 'Id'. Cannot convert the "VMware.Vim.Task" value of type "VMware.Vim.Task" to type "VMware.Vim.ManagedObjectReference".

At :line:12 char:18

+ $task = Get-View <<<< (Get-View($_.Extensiondata.ReconfigVM_Task($spec)))

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That line was really mixed up. There was 1 too many Get-View.

Corrected it.


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

0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

Again it configures for one VM and gives out this error,

Array assignment to [task-134165] failed: Cannot convert value "task-134165" to type "System.Int32". Error: "Input string was not in a correct format.".

At :line:12 char:10

+ $taskHash[ <<<< $task.Info.Key] = $task

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Apparently it wasn't my day when I entered that code in the post.

The $taskHash was defined as an array not as a hash table.

That is corrected now.


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

Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

Now it reconfigures 10 VM's and gives out this error. Can you please have a look?

As the tasks complete it does not not pick up other machines in the cluster for reconfiguration

An error occurred while enumerating through a collection: Collection was modified; enumeration operation may not execute..

At :line:14 char:7

+ foreach <<<< ($task in $taskHash.Values){

Message was edited by: Sureshadmin

Message was edited by: Sureshadmin

0 Kudos
LucD
Leadership
Leadership
Jump to solution

There was an error, you can't remove elements from a hash table while looping through the values.

Try this one (it works for me).

$nrMax = 10 
$taskHash = @{}

Get-Cluster <clu> | Get-VM | %{
  $spec = new-object VMware.Vim.VirtualMachineConfigSpec;
  $spec.cpuAllocation = New-Object VMware.Vim.ResourceAllocationInfo;
  $spec.cpuAllocation.Shares = New-Object VMware.Vim.SharesInfo;
  $spec.cpuAllocation.Shares.Level = "Normal";
  $spec.cpuAllocation.Limit = -1;
  $spec.cpuAllocation.Reservation = 0;
  $task = Get-View ($_.Extensiondata.ReconfigVM_Task($spec))
  $taskHash[$task.Info.Key] = $task

 
while($taskHash.Count -eq $nrMax){         $toBeRemoved = @()         foreach($task in $taskHash.Values){             $task.UpdateViewData()             if("success","error" -contains $task.Info.State){                 $toBeRemoved += $task.Info.Key             }         }         $toBeRemoved | %{              $taskHash.Remove($_)         }   } }


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

0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Perfect, it works!   Thanks a Ton!   Smiley Happy

0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

I have tried with plink and i'm able to login to the esx box, even the host key fingerprint is also present. But still the script runs for sometime but it doesn't show a error or a output. I'm running this against ESX 3.5 box. Can you pls look into it?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Could you tell what exactly you are trying to run via plink ?

Did you try interactively ? Did it show any messages ?


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

0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

hi Luc,

In the below given script i'm trying to retrive the datastore usage from each cluster by querying the first host of the cluster. The script runs fine. But at last row for each cluster i want a line with total capacity and total used capacity. But since there are hundreds of LUN's for each cluster the total value is so big and so it doesnt not get stored into the variable in proper format.

What type of variable do i declare $totalsize and $totalusize as?

$dsTab = @{}
$clusters = Get-Cluster
foreach  ($cluster in $clusters)
{
$vmhosts = $cluster | Get-VMHost
$fhost = $vmhosts[0]
$esxImpl = $fhost
$ds = $esxImpl | Get-Datastore | %{$dsTab[$_.Name] = $_}
$esxImpl | Get-VMHostStorage | %{
  $_.FileSystemVolumeInfo | %{
   $sizeGB = $_.Capacity/1GB
   $usedGB = ($_.Capacity/1MB - ($dsTab[$_.Name]).FreeSpaceMB)/1KB
   $usedPerc = $usedGB / $sizeGB
   $availGB = ($dsTab[$_.Name]).FreeSpaceMB/1KB
   $ds = Get-View $dsTab[$_.Name].Id
   $_ | select @{N="ESX Name";E={$esxImpl.Name}},
    @{N="Cluster Name";E={$cluster}},
    @{N="FS Name";E={$_.Name}},
    @{N="Type";E={$_.Type}},
    @{N="SizeGB";E={"{0:N1}" -f $sizeGB}},
    @{N="UsedGB";E={"{0:N1}" -f $usedGB}},
    @{N="AvailableGB";E={"{0:N1}" -f $availGB}},
    @{N="Used%";E={"{0:P1}" -f $usedPerc}},
    @{N="Mount point";E={$_.Path}}
    $totalsize += ($totalsize + $sizeGB)
    $totalusize += ($totalusize + $usedGB)
    }
  $totalsize
  $totalusize
}
}


0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can define them as double before at the start of the script

$totalsize = [double]0
$totalusize = [double]0


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

0 Kudos