Hello,
I want to delete the local disk of the all hosts after setup. First i have to find only the local disks on the hosts with powercli.
Could you help me?
Thanks.
I found those commands but it didnt work:
function Get-DatastoreHost {
Param(
[VMware.VimAutomation.Client20.DatastoreImpl] $Datastore,
[boolean] $IsConnected=$True
)
($Datastore | Get-View).Host | ForEach-Object { get-view -id $_.Key } | `
Where-Object { (-not $IsConnected) -or ($_.Runtime.ConnectionState -eq "connected") }
}
## This returns all local datastores on the specified Host
## We get all datastores, then find all the disknames they're on
## then select datastores where the disk object has class BlockHBA or ParallelSCSIHBA
function Get-LocalDatastore {
Param(
[VMware.VimAutomation.Client20.VMHostImpl] $VMHost
)
$LocalDevices=(Get-VMHostStorage -VMHost $VMHost | Get-View).StorageDeviceInfo.HostBusAdapter | `
Where-Object { `
($_.Key -like "key-vim.host.ParallelSCSIHBA-*") -or `
($_.Key -like "key-vim.host.BlockHBA-*") `
} | %{ [string]($_.Device) }
Get-Datastore -VMHost $VMHost | Where-Object {
(($_ | Get-View).Info.vmfs.extent | %{ ([string]$_.DiskName).split(":",2)[0]} ) `
-contains $LocalDevices
}
}
## This returns the DataCenter PS Object associated with a DataStore
## Basically goes through each Datastore in a Datacenter, and returns
## the data centers who Datastore URL's match our URL
## Only works for one input Data Center
function Get-DatastoreDatacenter {
Param(
$Datastore
)
Get-Datacenter | Where-Object {
(($_ | Get-View).Datastore | %{ (Get-View -Id $_).Summary.Url}) `
-contains (($Datastore | Get-View).Summary.Url)
}
}
## USAGE
$VMHost=@(Get-VMHost)[0] ## Gets the first host
$DS=@(Get-Datastore) [0] ## Gets the first datastore
"Get-LocalDatastore for host " + $VMHost.Name
Get-LocalDatastore -VMHost $VMHost | %{ $_.Name }
"=================="
"Get-DatastoreDatacenter for datacenter " + $DS.Name
(Get-DatastoreDatacenter -Datastore $DS).Name
"======================="
"Get-DatastoreHost for datacenter " + $DS.Name
Get-DatastoreHost -Datastore $DS -IsConnected $True | %{ $_.Name }
"================="