After finishing the last post and starting to use it after limited testing I found that my script wasn’t filtering out the Datastores as expected. This information was presented to me via our storage team. So I have went back to the Integrated Scripting Environment (ISE) to resolved my issues.
$Cluster = "Cluster name here" #This Line gets all of the LUNs that are connected to the first host in the cluster. $AllSCSILuns = (Get-Cluster $Cluster | Get-VMHost | Select -First 1 | Get-ScsiLun | Where {$_.LunType -eq "disk"}).CanonicalName #This line gathers all of the Datastores Connected to the cluster. $DataStoreVolumes = (Get-Cluster $Cluster | Get-VMHost | Get-Datastore | where {$_.Type -eq "VMFS"} | Get-View).info.VMFS.Extent.diskname #This does the first compare and removes the Datastores from the master list $DSRemoved = (Compare-Object -ReferenceObject $AllSCSILUNs -DifferenceObject $DataStoreVolumes).InputObject #This line gets all of the used RDM LUNs from the cluster $UsedSCSILUNs = (Get-Cluster $Cluster | Get-VMHost | Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual").ScsiCanonicalName | Sort -Unique #This does the final compare and removes the used RDM LUNs from the master list (Compare-Object -ReferenceObject $DSRemoved -DifferenceObject $UsedSCSILUNs).InputObjectThis is now how to properly get the unused RDM LUNs from your VM cluster.
– Stuart
Great work! Thanks for sharing.
having some errors using your script;
Compare-Object : Cannot bind argument to parameter ‘DifferenceObject’ because it is null.
At H:\VMware.PowerCLI\unused RDM LUNS.ps1:7 char:78
+ … erenceObject $AllSCSILUNs -DifferenceObject $DataStoreVolumes).InputO …
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Compare-Object], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CompareObjectCommand
Compare-Object : Cannot bind argument to parameter ‘ReferenceObject’ because it is null.
At H:\VMware.PowerCLI\unused RDM LUNS.ps1:11 char:34
+ (Compare-Object -ReferenceObject $DSRemoved -DifferenceObject $UsedSC …
+ ~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Compare-Object], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CompareObjectCommand
David,
Just from the output of the errors, it seems that the variables are not getting populated with the data to be able to compare them.
You might need to run this script a line at a time to see if the variables are getting populated with the needed data.
-Stuart
Thanks for the nice script.
I had to change $DataStores in line #5 to $DataStoreVolumes . It works after the change.
I see that it is listing local datastores also. It will be good if we can find a way to remove that too.
Mohamed,
Thanks for the correction on the script. Below is the change that you have asked for to remove the local datastore.