VMware Cloud Community
tomer133
Contributor
Contributor

VMware PowerCLI from VB.NET - Linked Mode vCenters

Hello,


I have a VB.net desktop application that connects to vCenter servers in linked mode to gather information.

I'm having an issue with some of the functions I am using, it appears that when running two PowerCLI commands one after the other (in the same subroutine within VB.net but separate commands for PowerCLI) only the first command gathers information for both vCenters...

I have attached a PDF file which explains my VMware environment arquitecture, and I've provided two examples that show sample code and sample outputs of the functions/cmdlets (test#1 and test#2).  As you can see from the file, only the functions that runs first gathers data from both vCenters, the second one only gathers data from the vCenter that it directly connects to; even though I always use the "-AllLinked" parameter.

Thanks!

0 Kudos
9 Replies
LucD
Leadership
Leadership

Any error messages ?

Can you try to leave out the ErrorAction parameter and check if you get messages ?

Can you do a Get-PowerCLIConfiguration in the scripts, just to check what is set for DefaultVIServerMode ?

Do these scripts show the same behavior when you execute them directly from the PowerCLI prompt, and not from a VB script ?


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

0 Kudos
tomer133
Contributor
Contributor

1. In TEST #2 , the second command is "Get-Datacenter | Select Name" instead of "Get-VM -Location Bogota | Select Name"


2.DefaultVIServerMode set to single and i get warning message about it .


3.these scripts show the same behavior when I execute them directly from the PowerCLI prompt


4.I added this command "Set-PowerCLIConfiguration -DefaultVIServerMode:Multiple -scope session -confirm:$false" and now it running correctly.

0 Kudos
LucD
Leadership
Leadership

Your DefaultVIServerMode is set to single it seems, you will have to change it permanently.

Make sure you do that for all scopes.


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

0 Kudos
tomer133
Contributor
Contributor

If I'll run the command as administrator for all scopes , will it be permanent?

0 Kudos
LucD
Leadership
Leadership

You need an account that can change the file %ProgramData%\VMware\PowerCLI\PowerCLI_Settings.xml.

Make sure to do this for all scopes.

Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope AllUsers,User,Session -Confirm:$false


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

0 Kudos
tomer133
Contributor
Contributor

From the PowerCLI command the functions in the different test scenarios run well,

But when I run it from within vb.net it only returns values for the vCenter I am using in the connection string.

0 Kudos
LucD
Leadership
Leadership

Could it be that the environment, which is normally done through the PowerCLI start, is not complete.

Do you have for example the global variable $global:defaultviservers ?

I suspect the PowerCLI cmdlets might be looking at that to find all the connections.


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

0 Kudos
tomer133
Contributor
Contributor

global variable  $global:defaultviservers and $global:defaultviserver returns null

When I try to disconnect between the two of scripts I get the following error :

You have modified the global:DefaultVIServer and global:DefaultVIServers system variables. This is not allowed. Please reset them to $null and reconnect to the vSphere server

0 Kudos
LucD
Leadership
Leadership

These variables should not be $null after you have done one or more Connect-VIServer


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

0 Kudos