VMware Cloud Community
Narayanan_5245
Enthusiast
Enthusiast

Orphaned disks script

Team - Can you anyone please suggest a simple script to check and report orphaned disks in all the datastores of the vCenter server.


Thank you

 

Regards

Narayanan.

Moderator edit by wila: Moved post to PowerCLI discussions

0 Kudos
17 Replies
LucD
Leadership
Leadership

Have a look at Orphaned Files Revisited


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast

Thanks LucD for the reply. I have tried this by saving it as Get-vmOrphan.ps1 and executed after connected to vCenter server, getting no output, and completing quickly

Is there anything i am executing the function incorrectly. Please advise.

 

Regards

Narayanan.

Tags (1)
0 Kudos
LucD
Leadership
Leadership

Did you actually call the function in your .ps1 file?
The Sample Usage in that post shows how to call the function.


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast

Kindly find below the output which followed the sample usage in the post.

PS C:\temp> Connect-VIServer vCenter01.globedev.com

Name Port User
---- ---- ----
vCenter01.globedev.com 443 root

PS C:\temp> .\Get-VmwOrphan.ps1
PS C:\temp> .\Get-VmwOrphan.ps1 -Datastore HDS-DEV-Vgstore
PS C:\temp>

 

Regards

Narayanan.

0 Kudos
LucD
Leadership
Leadership

That is not in the sample usage.

In the .ps1 file you copy the function, then at the end, you add one line where you call the function.

# Copy the function here

Get-VmwOrphan -Datastore HDS-DEV-Vgstore


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast

Hi LuCD

Copied the script into notepad and saved it as .ps1 file and add the last line (Get-VmwOrphan -Datastore HDS-DEV-Vgstore) which you suggested as well.

Connected the vCenter server. But it completes quickly and no output. Please advise if I executed incorrectly..

Narayanan_5245_0-1617268198219.png

Regards
Narayanan.

0 Kudos
LucD
Leadership
Leadership

Can you attach your script?


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast

Thanks for reply. PFA for your reference.

 

Regards

Narayanan.

0 Kudos
LucD
Leadership
Leadership

Is that a VSAN datastore?


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast

Hi LuCD,

No vsan datastores available in the environment.

All the datastores are configured with VMFS 5 version in the vCenter server.

I have tried with multiple datastores names & wild card asterisk as well.

Regards

Narayanan.

0 Kudos
LucD
Leadership
Leadership

Ok, can you try with the attached script?
That is my older version of the script.
Although the function is called Remove-OrphanedData, it will not remove any files unless the Delete switch is used.


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast

Thanks LuCD for checking. 
I have tried with the new script (script.ps1) which you attached and got the same with no output after connected to the vCenter, didnt throw any error as well.
Made a few of the vmdk disks unattached (removed from vm) in that datastores for testing as well.

Seems something I am missing.

Regards

Narayanan.

0 Kudos
LucD
Leadership
Leadership

Can you add the Verbose switch on the function call?
That function has verbose messages that could help to clarify what is happening.


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast

Hi LuCD,

Tried with a verbose option at the end of the line and got the below output. I could see you already added write-verbose in the function of the script.

PS C:\temp> .\script.ps1
VERBOSE: 4/6/2021 5:26:09 AM Get-View Started execution
VERBOSE: 4/6/2021 5:26:09 AM Get-View Finished execution
VERBOSE: 4/6/2021 5:26:09 AM Get-Datastore Started execution
VERBOSE: 4/6/2021 5:26:09 AM Get-Datastore Finished execution
VERBOSE: DS: HDS-DEV-Vgstore
VERBOSE: MultiHost: False
PS C:\temp>

Please advise.

 

Thank you

 

Regards

Narayanan.

Tags (1)
0 Kudos
LucD
Leadership
Leadership

The datastore doesn't seem to be a shared datastore.
Hence the function skips the check.


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

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast

ah..ok. you are right LuCD. 

just noticed the datastore LUNs are not presented to other hosts in the cluster.Let me try in different vCenter server where the datastores are shared across the hosts.

Is this possible to query all the VMFS datastores in the vCenter server except NFS and report orphaned vmdks?

Regards

Narayanan.

0 Kudos
LucD
Leadership
Leadership

Yes,  but to exclude NFS datastores, you will have to change the line

if ($ds.ExtensionData.Summary.MultipleHostAccess) {

into

if ($ds.ExtensionData.Summary.MultipleHostAccess -and $ds.Type -eq 'VMFS') {


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

0 Kudos