Hi Luc ,
would you like to check following function and suggest if anything needed to be modified .
this is to remove-datastore from each and every esxi in cluster.
since we dont have multiple vmhost option .
below is the code .
function dismount-datastores
{
[cmdletbinding()]
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[string[]]$datastores,
[Parameter(Mandatory=$true)]
[string]$clustername
)
$cluster=Get-Cluster $clustername
$vmhosts=(get-vmhost -Location $cluster).name
$vmhosts
#$report = @()
foreach($d in $datastores)
{
$datastore=Get-Datastore $d
$vms=get-vm -Datastore $datastore
#$output = New-Object -TypeName PSObject
#$output|Add-Member -MemberType NoteProperty -Name 'datastorename' -Value $datastore.name
#$output|Add-Member -MemberType NoteProperty -Name 'vmsindatastore' -Value $vms.name
#$report += $output
if($vms -eq $null)
{
for ($i=0; $i -lt $vmhosts.count;$i++)
{
Remove-Datastore -Datastore $datastore -vmhost $vmhosts[$i] -WhatIf
}
}
}
#$report|Out-GridView
}
That function should be ok, but removing a datastore requires more than just having no VMs on the datastore.
See my Test If The Datastore Can Be Unmounted post for a function that tests all possible reasons why a datastore can not be removed.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That function should be ok, but removing a datastore requires more than just having no VMs on the datastore.
See my Test If The Datastore Can Be Unmounted post for a function that tests all possible reasons why a datastore can not be removed.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc,
i found following after running your function:
however we are on 6.5 vsphereand if we go by webclient only two conditions should be met
If you look at KB2004605 there is a bit more listed, also for vSphere 6.5
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks Luc.
just thought of asking if you are part of powershellers community also ?
That group (not a community) was set up quite some time ago by a non-VMware person.
It is hardly used and I only very rarely look at it.
As far as I'm concerned that group could be removed, seen the overlap with the PowerCLI community.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i see you always reply .sometimes for non powercli questions also.
thnaks for massive global support .
is it fine if i can post some powershell specific questions here i mean not entirely powercli.
Sure, you would not be the first one :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks Luc.