Hi guys i am trying to automate my companies DR for VMware.
we replicate 8 vmware luns using our normal SAN technology and i have scripted taking a view on the latest PIT (point in time snapshot) and assigning it to 4 esx host that are in the the DataCenter "DR" and the cluster "DR Cluster"
I can use the PowerCLI to issue a rescan
get-vmhost | get-vmhoststorage -rescanallhba
this should make the datastores all pop in. (vmfs1,vmfs2,vmfs3 etc)
can i use the PowerCLI
$vmxpath = get-datastorefiles (get-datastore vmfs1) |
where { $_.Path -match '.vmx$' } | select path | % { Register-VM $_.Path
-vmhost (get-vmhost dresx.company.com) }
is there a way to register a VM to a cluster rather than a host? that way i dont need to worry about which ESX is being used for which VM, i can just let DRS deal with it when they are powered on.
Is there a simple way to tie these scripts together? is it possible to power all the VMs on and answer the VM question on wether to keep the uuid?
Have a look at , it contains a script to search a datastore for unregistered guests.
Yes, you can use a cluster by not specifying a host to the RegisterVM_Task method, provided the cluster is configured for DRS.
For answering guest questions see .
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Have a look at , it contains a script to search a datastore for unregistered guests.
Yes, you can use a cluster by not specifying a host to the RegisterVM_Task method, provided the cluster is configured for DRS.
For answering guest questions see .
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Quick question about rescanning hosts with powershell. I notice that using
Get-Cluster -Name $Cluster | Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs
results in the hosts being rescanned one at a time, in a serial fashion. It waits until one rescan task is done before it starts the next host. I notice that when i run the rescan function in the vspher VIC it seems to be able to scan all the hosts concurrently. Is there a way to do this in powershell? Thanks as always
Sean
I would not recommend rescanning all datastores at the same time. I know it's a lot quicker but it does cause a certain level of stress on your environment that you would want to avoid at anytime.
Duncan
VMware Communities User Moderator | VCP | VCDX
-
Available Soon: vSphere Quick Start Guide ()
If you find this information useful, please award points for "correct" or "helpful".
Great thanks for the recommendation. I was hoping to use this in our DR environment for some failover automation, hopefully that would be a use where it would be OK? Does anyone know how to do this in Powershell? Thanks
Sean
For DR purposes, rescanning the datastores like that shouldn't be a problem.
If you use the RescanHba method, you will have to wait till the scan is finished before you can start the next one.
There is no _Task version of this method!
The only way to bypass this apparently built-in feature is to use PowerShell v2 and use the Start-Process cmdlet.
In PowerShell v1 you could use the Community Extensions which also offer a Start-Process cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can loop through each host in the cluster use a rescanhba. That would be an option?
Im pretty new to scripting, does anyone know the basic syntax to using the Start-Process cmdlet to rescan all the datastores? I have Windows 7 with Powershell v2 installed and verified the Start-Process cmdlet is there. Thanks for the great help.
Sean
Rob, the RescanHba method doesn't come back to your script until the scan is finished.
You can loop through all your HBAs and launch the RescanHba with a Start-Process cmdlet.
You're in fact launching each RescanHba in it's own thread.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
From the top of my head I would tackle it this way.
-) in the main script loop through all the HBAs
-) for each HBA call a separate script through the Start-Process cmdlet, with the HBA as parameter, that will launch the RescanHba method
If you want I can give you some actual PowerShell code later
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect! I'll give it a try and let you know how it goes, thanks for the help.
LucD,
I have tried to craft a way to do this using the Start-Job cmdlet available in Powershell 2. I am trying to rescan all hosts in a cluster at the same time and not wait for each host scan to complete before the next one begins. Im having trouble getting it to runcorrectly andI cant find a wholelot of examples of this cmdlet online. Ive been trying stuff like this below with no success, i obviously have no clue how to use this cmdlet. Any help would be much appreciated. Thanks in advance.
Connect-ViServer "Vcenter"
$hosts = Get-Cluster "name of cluster" | Get-Vmhost
foreach ($machine in $hosts) {
Start-Job -ScriptBlock {
Add-PSSnapin Vmware.VimAutomation.Core
Connect-VIServer "Vcenter"
Get-Cluster "name of cluster" | Get-VMHost $machine | Get-VMHostStorage -RescanAllHba -RescanVmfs
Disconnect-VIServer -Confirm:$false
}
}