The backup jobs are getting failed due to GPT corruption (primary partition table) on the datastores.
Ran a command to check the status. However, we would like to check our entire environment to know how many datastores has similar issue.
so, is there a PowerCLI script available to determine LUN / datastore GPT corruption - Cluster wise or whole vCenter ? Could you please help here....!
You could do something like this.
It assumes that all your ESXi nodes use the same credentials.
It will start (and stop) the SSH service when it is not running on an ESXi node.
$pswd = 'VMware1!'
$secPswd = ConvertTo-SecureString $pswd -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $secPswd
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$service = Get-VMHostService -VMHost $esx | where { $_.Key -eq 'TSM-SSH' -and -not $_.Running } |
Start-VMHostService -Confirm:$false
$session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey
Get-Datastore -RelatedObject $esx -PipelineVariable ds |
where { $_.Type -eq 'VMFS' } |
ForEach-Object -Process {
$ds.ExtensionData.Info.Vmfs.Extent |
ForEach-Object -Process {
Write-Host -ForegroundColor Yellow "ESXI $($esx.Name) DS $($ds.Name) Extent $($_.DiskName)"
$dev = $_.DiskName
$cmd = "partedUtil getptbl /vmfs/devices/disks/$dev"
$result = Invoke-SSHCommand -SSHSession $session -Command $cmd
$result.OutPut
}
}
Remove-SSHSession -SSHSession $session | Out-Null
if ($service)
{
Stop-VMHostService -HostService $service -Confirm:$false | Out-Null
}
}
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Which command did you run?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here is the command that I ran to determine by using each LUN naa id -
I ran this command by logging into one of the ESXi host via SSH
partedUtil getptbl /vmfs/devices/disks/naa.ID
Is SSH enabled on your ESXi nodes?
Or can it be started temporarily?
If yes, you could use the Posh-SSH module (see my Use Posh-SSH instead of PuTTY post), to run that command on each ESXi nodes for each datastore.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
when ever needed, we will start the SSH service, otherwise, it will be in stopped state.
You could do something like this.
It assumes that all your ESXi nodes use the same credentials.
It will start (and stop) the SSH service when it is not running on an ESXi node.
$pswd = 'VMware1!'
$secPswd = ConvertTo-SecureString $pswd -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $secPswd
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$service = Get-VMHostService -VMHost $esx | where { $_.Key -eq 'TSM-SSH' -and -not $_.Running } |
Start-VMHostService -Confirm:$false
$session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey
Get-Datastore -RelatedObject $esx -PipelineVariable ds |
where { $_.Type -eq 'VMFS' } |
ForEach-Object -Process {
$ds.ExtensionData.Info.Vmfs.Extent |
ForEach-Object -Process {
Write-Host -ForegroundColor Yellow "ESXI $($esx.Name) DS $($ds.Name) Extent $($_.DiskName)"
$dev = $_.DiskName
$cmd = "partedUtil getptbl /vmfs/devices/disks/$dev"
$result = Invoke-SSHCommand -SSHSession $session -Command $cmd
$result.OutPut
}
}
Remove-SSHSession -SSHSession $session | Out-Null
if ($service)
{
Stop-VMHostService -HostService $service -Confirm:$false | Out-Null
}
}
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
excellent, that is working the way I expected. Thank you so much.
However, can the output be captured in a tabular format like below in a spread sheet please:
vCenter name, ESXi host name, datastore name, naa.id, GPT status
TIA
And what do you consider to be the 'GPT status' in the output of the command?
Or how would you derive that?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
One way I could think of is to check if the partition table is at least present.
If not, the command will only return the top 2 lines.
Would that cover your case?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
this is how the output is showing up when I run the script -
ESXI esxhost1.com DS NR_122_ha_v6 Extent naa.600507680c808602e8000000000000b5
gpt
133674 255 63 2147483648
1 2048 2147483614 AA31E02A400F11DB9590000C2911D1B8 vmfs 0
in the fist line, listing the ESXi host name with datastore name along with naa ID number
under GPT status, script should be able to capture the data apart from the first line.
Sorry, not following.
Could you perhaps show me an example of the output as you would like to see it?
Remember, a partition can consist of multiple lines.
How would you display those?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That is what it currently shows.
My question is, what, and how, do you want it to show?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I would like to capture from "gpt to vmfs 0" (between what ever the text), under "GPT status" column.
Ok, try like this
$pswd = 'VMware1!'
$secPswd = ConvertTo-SecureString $pswd -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $secPswd
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$service = Get-VMHostService -VMHost $esx | where { $_.Key -eq 'TSM-SSH' -and -not $_.Running } |
Start-VMHostService -Confirm:$false
$session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey
Get-Datastore -RelatedObject $esx -PipelineVariable ds |
where { $_.Type -eq 'VMFS' } |
ForEach-Object -Process {
$ds.ExtensionData.Info.Vmfs.Extent |
ForEach-Object -Process {
$dev = $_.DiskName
$cmd = "partedUtil getptbl /vmfs/devices/disks/$dev"
$result = Invoke-SSHCommand -SSHSession $session -Command $cmd
New-Object -TypeName PSObject -Property ([ordered]@{
vCenter = ([uri]$esx.ExtensionData.Client.ServiceUrl).Host
VMHost = $esx.Name
Datastore = $ds.Name
DiskName = $dev
'GPT Status' = $result.Output -join ' '
})
}
}
Remove-SSHSession -SSHSession $session | Out-Null
if ($service)
{
Stop-VMHostService -HostService $service -Confirm:$false | Out-Null
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks, it is displaying on the screen, but, the output is not saving in the .csv format
Add the following at the end
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes, I've already tried adding the below, but, it not working -
Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Did you add the vertical bar (pipeline symbol)?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks much for your time. its a great help.