Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

Latency to be available to execute commands

$
0
0

Hi,

I have setup a full powershell script in order to duplicate a master from 1 vCenter to another one.

The way I am doing it is by snapmirroring (netapp storage) the volume where my Master is, then clone the lmast snapshot within the snapmirror and attach this clone a regular datastore to the 2nd vCenter.

The issue I am facing is that in order to complete the storage attachment to my vCenter, I need to wait for something, but what ?, in order for the command to operate.

 

Pratically, here is the script

 

Connect-VIServer myvcenter
$servers = Get-VMHost -location "MYCLUSTER"
$server = Get-VMHost | WHERE {$_.Name -eq "myesxi.local.com"}
Get-VMHostStorage -VMHost $server -RescanAllHba

Get-Datastore -VMHost $server.Name -Refresh

 

Then I enable SSH in order to pull the details for mapping the storage

 

Start-VMHostService -HostService ($server | Get-VMHostService | Where { $_.key -eq "TSM-SSH"})
$User = "root"
$Pswd = "xxxxxxxxxx"
$Computer = "myesxi.local.com"
$plink = "c:\Scripts\plink.exe"
$plinkoptions = " -ssh -pw $Pswd"

$remoteCommand = "`"esxcfg-volume -l`""

$command = $plink + " " + $plinkoptions + " " + $User + "@" + $computer + " " + $remoteCommand

$Resultat = Invoke-Expression -command $command

 

And this is where my 1st problem starts. I need to run that last command 6 or 7 time for it to give me the right result.

Once this works I continue with this where I have the exact same issue

 

$UUID = (($Resultat[0].Split(" "))[2].Split("/"))[0]

$remoteCommand = "esxcfg-volume -M `"$UUID`""
$command = $plink + " " + $plinkoptions + " " + $User + "@" + $computer + " " + $remoteCommand
Invoke-Expression -command $command

Stop-VMHostService -HostService ($server | Get-VMHostService | Where { $_.key -eq "TSM-SSH"}) -Confirm:$false

Get-Datastore -VMHost $server.Name -Refresh

 

It takes a very long time the Get-Datastore -Refresh to show my the last datastore attached to my ESXi ?

 

Am I doing something wrong or the bad way ?

Should I wait for some results from something in order to be able to run that script one shot ?

 

Many thanks in advance for your lights


Viewing all articles
Browse latest Browse all 179681

Trending Articles