VMware Cloud Community
David2021
Contributor
Contributor
Jump to solution

Script to check prerequisite to unmount datastores: CoreDump

Hello,

I found this link:  Script of LucD done by LucD.

I need some help to add a new verification concerning coredump in this same script. By default the folder is vmkdump on datastore but maybe the name could be modify. So I'm sure that this function is accurate for example.

# No CoreDump partition
No_CoreDump_Partition = &{
New-PSDrive -Location $ds -Name ds -PSProvider VimDatastore -Root '\' | Out-Null
$result = Get-ChildItem -Path ds:\ -Recurse |
where {$_.Name -match 'vmkdump'}
Remove-PSDrive -Name ds -Confirm:$false
if($result){$false}else{$true}

If someone can help me on an other approach to insert in this existing script?

regards,
David

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try with this version

function Get-DatastoreUnmountStatus {
    <#
.SYNOPSIS  Check if a datastore can be unmounted.
.DESCRIPTION The function checks a number of prerequisites
that need to be met to be able to unmount a datastore.
.NOTES  Author:  Luc Dekens
.PARAMETER Datastore
The datastore for which you want to chekc the conditions.
You can pass the name of the datastore or the Datastore
object returned by Get-Datastore
.EXAMPLE
PS> Get-DatastoreUnmountStatus -Datastore DS1
.EXAMPLE
PS> Get-Datastore | Get-DatastoreUnmountStatus
#>
    param(
        [CmdletBinding()]
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [PSObject[]]$Datastore
    )
    process {
        foreach ($ds in $Datastore) {
            if ($ds.GetType().Name -eq "string") {
                $ds = Get-Datastore -Name $ds
            }
            $parent = Get-View $ds.ExtensionData.Parent
            New-Object PSObject -Property ([ordered]@{
                Datastore = $ds.Name
                # No Virtual machines
                NoVM = $ds.ExtensionData.VM.Count -eq 0
                # Not in a Datastore Cluster
                NoDastoreClusterMember = $parent -isnot [VMware.Vim.StoragePod]
                # Not managed by sDRS
                NosDRS = & {
                    if ($parent -is [VMware.Vim.StoragePod]) {
                        !$parent.PodStorageDrsEntry.StorageDrsConfig.PodConfig.Enabled
                    } else { $true }
                }
                # SIOC disabled
                NoSIOC = !$ds.StorageIOControlEnabled
                # No HA heartbeat
                NoHAheartbeat = & {
                    $hbDatastores = @()
                    $cls = Get-View -ViewType ClusterComputeResource -Property Host |
                    Where-Object { $_.Host -contains $ds.ExtensionData.Host[0].Key }
                    if ($cls) {
                        $cls | ForEach-Object {
                            (                $_.RetrieveDasAdvancedRuntimeInfo()).HeartbeatDatastoreInfo | ForEach-Object {
                                $hbDatastores += $_.Datastore
                            }
                        }
                        $hbDatastores -notcontains $ds.ExtensionData.MoRef
                    } else { $true }
                }
                # No vdSW file
                NovdSwFile = & {
                    New-PSDrive -Location $ds -Name ds -PSProvider VimDatastore -Root '\' | Out-Null
                    $result = Get-ChildItem -Path ds:\ -Recurse |
                    Where-Object { $_.Name -match '.dvsData' }
                    Remove-PSDrive -Name ds -Confirm:$false
                    if ($result) { $false }else { $true }
                }
                # No scratch partition
                NoScratchPartition = & {
                    $result = $true
                    $ds.ExtensionData.Host | ForEach-Object { Get-View $_.Key } | ForEach-Object {
                        $diagSys = Get-View $_.ConfigManager.DiagnosticSystem
                        $dsDisks = $ds.ExtensionData.Info.Vmfs.Extent | ForEach-Object { $_.DiskName }
                        if ($dsDisks -contains $diagSys.ActivePartition.Id.DiskName) {
                            $result = $false
                        }
                    }
                    $result
                }
                # No vmkdump
                NoVmkDumpFolder = &{
                        $url = $ds.ExtensionData.Summary.Url.Replace('ds://','')
                        $result = Get-VMHost -Datastore $ds -PipelineVariable esx |
                        ForEach-Object -Process {
                            $esxcli = Get-EsxCli -VMHost $esx -V2
                            $esxcli.system.coredump.file.list.Invoke() | where{$_.Active -and $_.Path -match $url}
                        }
                        if($result){$false}else{$true}
                }
            })
        }
    }
}


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

View solution in original post

Reply
0 Kudos
14 Replies
LucD
Leadership
Leadership
Jump to solution

Try with this version

function Get-DatastoreUnmountStatus {
    <#
.SYNOPSIS  Check if a datastore can be unmounted.
.DESCRIPTION The function checks a number of prerequisites
that need to be met to be able to unmount a datastore.
.NOTES  Author:  Luc Dekens
.PARAMETER Datastore
The datastore for which you want to chekc the conditions.
You can pass the name of the datastore or the Datastore
object returned by Get-Datastore
.EXAMPLE
PS> Get-DatastoreUnmountStatus -Datastore DS1
.EXAMPLE
PS> Get-Datastore | Get-DatastoreUnmountStatus
#>
    param(
        [CmdletBinding()]
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [PSObject[]]$Datastore
    )
    process {
        foreach ($ds in $Datastore) {
            if ($ds.GetType().Name -eq "string") {
                $ds = Get-Datastore -Name $ds
            }
            $parent = Get-View $ds.ExtensionData.Parent
            New-Object PSObject -Property ([ordered]@{
                Datastore = $ds.Name
                # No Virtual machines
                NoVM = $ds.ExtensionData.VM.Count -eq 0
                # Not in a Datastore Cluster
                NoDastoreClusterMember = $parent -isnot [VMware.Vim.StoragePod]
                # Not managed by sDRS
                NosDRS = & {
                    if ($parent -is [VMware.Vim.StoragePod]) {
                        !$parent.PodStorageDrsEntry.StorageDrsConfig.PodConfig.Enabled
                    } else { $true }
                }
                # SIOC disabled
                NoSIOC = !$ds.StorageIOControlEnabled
                # No HA heartbeat
                NoHAheartbeat = & {
                    $hbDatastores = @()
                    $cls = Get-View -ViewType ClusterComputeResource -Property Host |
                    Where-Object { $_.Host -contains $ds.ExtensionData.Host[0].Key }
                    if ($cls) {
                        $cls | ForEach-Object {
                            (                $_.RetrieveDasAdvancedRuntimeInfo()).HeartbeatDatastoreInfo | ForEach-Object {
                                $hbDatastores += $_.Datastore
                            }
                        }
                        $hbDatastores -notcontains $ds.ExtensionData.MoRef
                    } else { $true }
                }
                # No vdSW file
                NovdSwFile = & {
                    New-PSDrive -Location $ds -Name ds -PSProvider VimDatastore -Root '\' | Out-Null
                    $result = Get-ChildItem -Path ds:\ -Recurse |
                    Where-Object { $_.Name -match '.dvsData' }
                    Remove-PSDrive -Name ds -Confirm:$false
                    if ($result) { $false }else { $true }
                }
                # No scratch partition
                NoScratchPartition = & {
                    $result = $true
                    $ds.ExtensionData.Host | ForEach-Object { Get-View $_.Key } | ForEach-Object {
                        $diagSys = Get-View $_.ConfigManager.DiagnosticSystem
                        $dsDisks = $ds.ExtensionData.Info.Vmfs.Extent | ForEach-Object { $_.DiskName }
                        if ($dsDisks -contains $diagSys.ActivePartition.Id.DiskName) {
                            $result = $false
                        }
                    }
                    $result
                }
                # No vmkdump
                NoVmkDumpFolder = &{
                        $url = $ds.ExtensionData.Summary.Url.Replace('ds://','')
                        $result = Get-VMHost -Datastore $ds -PipelineVariable esx |
                        ForEach-Object -Process {
                            $esxcli = Get-EsxCli -VMHost $esx -V2
                            $esxcli.system.coredump.file.list.Invoke() | where{$_.Active -and $_.Path -match $url}
                        }
                        if($result){$false}else{$true}
                }
            })
        }
    }
}


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

Reply
0 Kudos
David2021
Contributor
Contributor
Jump to solution

Hello LucD

If I understand, your proposition verify if there is a coredump is set on ESXi right?

# No vmkdump
NoVmkDumpFolder = &{
$url = $ds.ExtensionData.Summary.Url.Replace('ds://','')
$result = Get-VMHost -Datastore $ds -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.system.coredump.file.list.Invoke() | where{$_.Active -and $_.Path -match $url}
}
if($result){$false}else{$true}
}

 

My request is to verify the existance of coredump file and folder on datastore vmfs. I have configured this:

# No CoreDump partition
No_CoreDump_Partition = &{
  New-PSDrive -Location $ds -Name ds -PSProvider VimDatastore -Root '\' | Out-Null
  $result = Get-ChildItem -Path ds:\ -Recurse |
  where {$_.Name -match 'vmkdump' -or $_.Name -like '*.dumpfile'}
  Remove-PSDrive -Name ds -Confirm:$false
  if($result){$false}else{$true}
}

Can you explain what is the difference between these 2 propositions.

regards,

David

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

My code checks on all ESXi nodes that have the Datastore configured if there is an "active" dump.


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

Reply
0 Kudos
David2021
Contributor
Contributor
Jump to solution

If I understand your code check if an active dump exist between all ESXi nodes and a Datastore so if there is a configuration between them.

I request your opinion what is the best or accurate between these 2 codes for you: one check existence of folder and files on datastore and one check if there is an active dump configure between ESXi servers and Datstore? Maybe use both?

For you information, I check prerequisites including these codes in particular before to remove and detach Datastore from ESXi.

regards,
David

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Depends on what you want to achieve.

To check if there is a folder, and dump file, on the datastore, active or not active, might be useful when you want to first check if that dump should be safeguarded before removing the datastore.

To check if there is an active dump file avoids having an issue with unmounting the datastore.



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

Reply
0 Kudos
David2021
Contributor
Contributor
Jump to solution

OK LucD

Regarding your script Get-DatastoreUnmountStatus which is very good, I have a point I export in csv file:

How I can set a specify order of column for Datastore, NoVM, NoDastoreClusterMember, NosDRS, NoSIOC, NoHAheartbeat, NovdSwFile, NoScratchPartition. Currently, if I rename one of them inside the script the order of column change randomly without sens and no alphabetical order. The column name of datastore are the lastest column and I prefer that it's first column for example.


regards,
David

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The code above contains

New-Object PSObject -Property ([ordered]@{

which should make the order fixed.


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

Reply
0 Kudos
David2021
Contributor
Contributor
Jump to solution

OK - This add-on code resolve the point to put the column name of datastore in first column in csv file.

But the rest of NoVM, NoDastoreClusterMember, NosDRS, NoSIOC, NoHAheartbeat, NovdSwFile, NoScratchPartition are not order but nevermind it's design.

 

Last point:

The check Datastore Hearbeat is based on which of these 3 options ?
- Automatically select datastores accessible from the hosts (normaly is the default option on ESXi cluster)
- Use datastores only from the specified list
- Use datastores from the specified list and complement automatically if needed
Or other points ?
Because I have a datastore which for that point NoHAheartbeat is "False" but there is nothing particular it's default option regarding the other datastores with the result "True"

 

regards,

David

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik, the RetrieveDasAdvancedRuntimeInfo method returns the used datastore(s), independent of which datastore selection method is defined. 


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

Reply
0 Kudos
David2021
Contributor
Contributor
Jump to solution

Ok LucD

When I use your code, the execution is more longer but it's maybe normal because each ESXi servers is check multiply by number of datastore.

# No vmkdump
NoVmkDumpFolder = &{
$url = $ds.ExtensionData.Summary.Url.Replace('ds://','')
$result = Get-VMHost -Datastore $ds -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.system.coredump.file.list.Invoke() | where{$_.Active -and $_.Path -match $url}
}
if($result){$false}else{$true}
}

The incident that I have this message in powerCLI window : "WARNING: PowerCLI scripts should not use the 'DatastoreIdList' property of VMHost type. The property will be removed in a futur release."

The prompt is stuck and not give back hand automaticaly whereas the csv file is already created. I need to Ctrl + C to stop and give back hand for the prompt

 

regards,

David

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is but a warning, and can safely be ignored.
If you want to avoid those type of warnings, use the Set-PowerCLIConfiguration cmdlet and set the DisplayDeprecationWarnings to $false for all scopes.

The script works perfectly for me.
No hang at the end.
Is one of the ESXi nodes on which the datastore is known perhaps powered off?

The columns are exported in the order defined in the New-Object statement.
I have no clue why that wouldn't work for you.


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

Reply
0 Kudos
David2021
Contributor
Contributor
Jump to solution

Hello LucD,

 

It's OK.

 

This part is long to execute to the end - that's all. I need to be patient. The execution time depends of number of ESXi servers and datastores.

# No vmkdump
NoVmkDumpFolder = &{
$url = $ds.ExtensionData.Summary.Url.Replace('ds://','')
$result = Get-VMHost -Datastore $ds -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.system.coredump.file.list.Invoke() | where{$_.Active -and $_.Path -match $url}
}
if($result){$false}else{$true}
}

 

Thanks a lot for your support on that subject. Your scripts are accurate and helpful to manage Vmware environement.

Regard,

David

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

And another one where your reply is the solution 🤔


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

Reply
0 Kudos
David2021
Contributor
Contributor
Jump to solution

Sorry LucD you right. It's more accurate to your proposition.

I corrected to your post.

Reply
0 Kudos