VMware Cloud Community
Sergei13
Enthusiast
Enthusiast

Difference between interactive session and "batch mode"

HI,

To make a long story short, I put together a bunch of scripts I used to manage my storage (NetApp - Powershell Dataontap) and my hypervisors (VMware - Powercli) and added a GUI made with Sapiens tool.

This works fine, I can select what I want in comboxes go all the way from selecting volume, cloning storage volume, adding datastore to my hypervisors ..., to adding VM to inventory and starting them.

Based on this and using the same interface, I added a batch mode meaning I pass a text file with instructions that are interpreted to kick the actions as if I was click on the forms buttons and comboboxes.

My problem is specifically on the part where I scan my Esxi to find if I have a new datastore available.

I use the following powercli command to do this :

     $Esxcli = Get-Esxcli -VMHost $Hyperviseurs.SelectedItem

For some reasons, if I run the command manually and when I click on the button to scan, it works fine.

In my "batch mode", the exact same code runs in no time and obviously returns nothing !

Since I am using the exact same code, just that one one side it is called from the event and on the other, called from a function, I don't understand why only this wouldn't work.

To me, the only difference I see is in the way to call the form.

In interactive mode, I do

     $form1.ShowDialog()| Out-Null

while in batch mode I do :

     $form1.Show()

     $form1.refresh()

     $form1.Activate()

If someone has an idea, very welcome since I have been waisting my most of my last nights trying to figure this out.

Alternatively, if I can't get it towork this way, is there any other way to scan new for new datastore ?

Many thanks in advance for your help.

M

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership

Are you sure you initiate a scan with only the line ?

     $Esxcli = Get-Esxcli -VMHost $Hyperviseurs.SelectedItem


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Sergei13
Enthusiast
Enthusiast

Sorry, you are right.

First, I do:

     Get-VMHostStorage -VMHost $Hyperviseurs.SelectedItem -RescanAllHba

And then

     $Esxcli = Get-Esxcli -VMHost $Hyperviseurs.SelectedItem

     $NewLun = $Esxcli.storage.vmfs.snapshot.list()

Reply
0 Kudos
LucD
Leadership
Leadership

That's what I suspected Smiley Wink

Did you try adding a line with

Get-VMHostStorage -VMHost $Hyperviseurs.SelectedItem -RescanVmfs

The RescanAllHBA switch is not the same as the Rescan All in the vSphere client.

But that doesn't explain why it works in the GUI, unless it is a timing issue.

Your "batch" will most probably run faster than the GUI


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Sergei13
Enthusiast
Enthusiast

Thank you Luc, I am gonna try this.

I also initially suspected a tempo issue hence I added a command (sounds impressive doesn't it :smileymischief:) tempo in order to wait for n seconds.

But that made no difference Smiley Sad

Reply
0 Kudos
Sergei13
Enthusiast
Enthusiast

.... sorry, a stupid question but doesn't the sequence matter ?

Meaning is it important to do RescanVmfs after RescanAllHba ?

Reply
0 Kudos
LucD
Leadership
Leadership

Yes, do the VMFS rescan after the HBA rescan.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Sergei13
Enthusiast
Enthusiast

Unfortunatelly this makes no difference :smileycry:

I have been going thru my code up and down and I can't figure out why this would behave differently :smileyangry:

That doesn't make sens at all

Reply
0 Kudos
Sergei13
Enthusiast
Enthusiast

Just for the sake of it and if someone was running into the same issue, the only way I got it to work is scan an other ESXi and then rescan the exact same ESXi.

This way I can see my new Datastore.

Reply
0 Kudos