Hi,
i trying but i don't get the desired result with my script.
We use NAS, SDN (over FC and ip) storage solutions.
My task is to shut down all VM which use certain storage(datastore)
Get-VM | Select Name , powerstate , @{N =“Datastore”;E= {$_ |Get-Datastore | where{$_.Type -eq 'VMFS'} | Select Name, @{N='Stor_Dev';E={$_.ExtensionData.Info.Vmfs.Extent.DiskName -join ' | '}}}} | Out-GridView
with script I get all VM that use VMFS file system ( SAN and FC storage ) but I need to separate that,
when I get right result with command and do export to file than I try with script below:
foreach($vmlist in (Get-Content -Path C:\TEMP\vm_shutdown.txt))
{
$vm = Get-VM -Name $vm_shotdown
Shutdown-VMGuest -VM $vm -Confirm:$false
}
just to mention that some vm dont have installed vm-tools.
Can you check if the following returns the datastores that sit on LUNs with a canonicalname starting with 'naa'.
If it does, you would just need to add a Get-VM after the where-clause.
$canonical = Get-ScsiLun -VmHost $esx -CanonicalName naa* | select -ExpandProperty CanonicalName
Get-Datastore -RelatedObject $esx |
where{$canonical -contains $_.ExtensionData.Info.VMFS.Extent.DiskName}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could turn this around start with the datastores of a specific type.
Then get the VMs on those datastores.
If the VMware Tools are running, do a graceful guest OS shutdown.
If not, stop the VM.
ForEach-Object -Process {
if($_.Guest.GuestState -eq 'running'){
Shutdown-VMGuest -VM $_ -Confirm:$false
}
else{
Stop-VM -VM $_ -Confirm:$false
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ok, but how do i separate the vm they use FC storage from vm that use SDS storage?
i thought i was using the storage device name but it fails to make the correct script.
What do you mean by
with script I get all VM that use VMFS file system ( SAN and FC storage ) but I need to separate that,
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There are two storages. One is connected through FC and the second one is connected over IP
Do you mean FC vs FCoE?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes
You should see different HBA for both.
What does this show?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
get-vmhost -Name 10.33.33.4 | Get-VMHostHba -Type FibreChannel
Device Type Model Status
------ ---- ----- ------
vmhba2 FibreChannel Emulex LPe12000 8Gb PCIe Fi... online
vmhba3 FibreChannel Emulex LPe12000 8Gb PCIe Fi... online
vmhba64 FibreChannel online
Can you check if the following returns the datastores that live on FCOE adapters?
$esxcli = Get-EsxCli -VMHost $_ -v2
$fcoeAdapters = $esxcli.storage.san.fcoe.list.Invoke() | Select -ExpandProperty Adapter
$fcoeAdapters
$fcoeDevices = $esxcli.storage.core.path.list.Invoke() | where{$fcoeAdapters -contains $_.Adapter} | Select -ExpandProperty Device
$fcoeDevices
$dsNames = $esxcli.storage.vmfs.extent.list.Invoke() | where{$fcoeDevices -contains $_.DeviceName} | Select -ExpandProperty VolumeName
$dsNames
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
no , there is no error but also there is nothing to display
That looks as if there are no FCoE adapters.
Or which of the 3 adapters you showed earlier are the FCoE adapters?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ok, I must start from begin .
There are six esxi hosts
Get-Datastore | where{$_.Type -eq 'NFS'} | Get-VM -- all vms on NAS
Get-Datastore | where{$_.Type -eq 'VMFS'} | Get-VM -- all VM on VMFS , result is all VM that use two storages and I need to separate that output
with
Get-VMHost | Get-ScsiLun -CanonicalName eui* | Out-GridView - result all identifier for lun on one storage ( multiple 5 for each host )- I need to get all vm and their state ,
Get-VMHost | Get-ScsiLun -CanonicalName naa* | Out-GridView - result all identifier for lun on second storage ( multiple 5 for each host ) I need to get all vm and their state ,
This is becoming rather confusing.
So you have VMs that are located on both types of datastores?
What needs to be done with those VMs? Do they need an svMotion?
Is that the qualifying criterium?
LUN whose canonicalname starts with 'eui' are on which type of storage?
Same for LUNs whose canonicalname starts with 'naa'.
What exactly is the question now?
Do VMs on a specific type of datastore storage need to be stopped?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So you have VMs that are located on both types of datastores? --- Yes
What needs to be done with those VMs? Do they need an svMotion? to be shot down , svmotion -- NO, because leter on that vm will power on
Same for LUNs whose canonicalname starts with 'naa' -- yes fc storage
Do VMs on a specific type of datastore storage need to be stopped? -- Yes
Can you check if the following returns the datastores that sit on LUNs with a canonicalname starting with 'naa'.
If it does, you would just need to add a Get-VM after the where-clause.
$canonical = Get-ScsiLun -VmHost $esx -CanonicalName naa* | select -ExpandProperty CanonicalName
Get-Datastore -RelatedObject $esx |
where{$canonical -contains $_.ExtensionData.Info.VMFS.Extent.DiskName}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes , that will do. Thanks LucD.
foreach($esx in Get-VMHost){
$canonical = Get-ScsiLun -VmHost $esx -CanonicalName eui* | select -ExpandProperty CanonicalName
}
Get-Datastore -RelatedObject $esx
where{$canonical -contains $_.ExtensionData.Info.VMFS.Extent.DiskName} | get-vm