VMware Cloud Community
THaus
Contributor
Contributor
Jump to solution

Newbie PowerGui Question

Newbie PowerGui Question - I have PowerGui successfully installed with the powerpack and connected to a Virtual Center. I have a strange side effect though ... When using the "connect" out of the vmware folder for the virtual center that has been created all of the canned vmware scripts under that folder work as expected. I am able to see the VMs, snapshots, etc.

If I create a script under the vmware folder or under a folder that I created it loses the VC inheritance from the connection i.e. the script error prompts needing "connect-viserver. What is missing on this or what did I forget as this only started occuring after logging out and then back in.

What did I do ... any ideas

Any help will be appreciated

Tedd

Reply
0 Kudos
1 Solution

Accepted Solutions
DSotnikov
Enthusiast
Enthusiast
Jump to solution

For script nodes to work you would need to either:

  • start PowerGUI as VI Client plugin, or

  • add Connect-VI-Server to your PowerShell profile, or

  • add the -Server $global:VIServer to your scripts.

My guess is that scripts could have worked before because the tool was started from VI Client Plugins menu.

The issue is really with VI cmdlets and the way the connection is handled. When you connect from PowerGUI itself the connection is made from the corresponding Connect action which is a PowerShell function. For some reason, when you connect to VI Server from a function this connection is not always available for other functions, unless you use that-Server parameter. This is a bit weird and I hope someone from VMware can chime in.

View solution in original post

Reply
0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

It looks as if you need to add -Server $global:VIServer to the cmdlets in your script.

I just tried this sample script and it only works when I add the -Server parameter.

Get-VM -Server $global:VIServer


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

Reply
0 Kudos
halr9000
Commander
Commander
Jump to solution

LucD already came up with this but I thought you guys might like to see what Dmitry from Quest had to say:

>There are couple of workarounds you can try:

>A. Start PowerGUI as a plugin from VI Client.

>B. In your script explicitly tell the cmdlets to use the server connection by adding “-Server $global:VIServer”. E.g.:

>Get-VM -Server $global:VIServer

>Adds a few extra characters but at least you don’t have to re-connect to the VI Server.

>Dmitry

>See also: Dmitry's PowerBlog at http://dmitrysotnikov.wordpress.com






Author of the upcoming book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
THaus
Contributor
Contributor
Jump to solution

Thanks for the answers but it looks like this is a restiction issue to newly created scripts. It is as if powergui isn't trusting or is restricting the newly created scripts. The inheritance from the Virtual Center connection is not applied to any new scripts only what is is in the initial powerpack.

An example of this is if I create an identical node to the "Virtual Machines" where it has get-vm

Clicking on what was imported from the powerpack display all vms

Clicking on a identical node to this that I created demostrated the need to connect-viserver.

both of these are identical but yet one of them doesn't work.

Also, all my new scripts worked unti logging out of the OS and then back in, It as if I powergui lost a preference or setting.

Any ideas what needs to be done to powergui?

Reply
0 Kudos
DSotnikov
Enthusiast
Enthusiast
Jump to solution

Tedd,

I swear that there is no preferential treatment in PowerGUI. Smiley Happy

Could you copy/paste (or attach screanshot) of the PowerShell Code tab after you click the standard Virtual Machines node (which is working) and your node (which is not)?

This should let us see if there are any differences.

Dmitry

Reply
0 Kudos
THaus
Contributor
Contributor
Jump to solution

If I work around the issue by adding connect-viserver to the begginning of the scripts in powergui that were working the script error is gone and they will execute. However, now that this line is there in powergui the output is only the virtualcenter connection information. Any output for the actual script is lost because of what was formatted for the virtualcenter connection in the powergui window. Whatever results are expected are now empty cloumns and rows inside powergui as the connect-viserver.

This is not a powershell issue as the output is fine as the script will make the connection and then display the results. Is there anyway to suppress the connection for the virtualcenter when doing this in powergui so it doesn't display connection results thus blanking out the results of the actual script. The columns for the actual script will not match the 3 columns that connect-viserver create. What I used to see before this problem for example was 50 rows of information generated by a powergui script. Now that I am losing inheritance and adding a connect-viserver line I see 51 lines of output, 1 line for the virtualcenter connection with 3 columns and then 50 rows underneath because the column names don't actually match.

Ideas???

Reply
0 Kudos
DSotnikov
Enthusiast
Enthusiast
Jump to solution

Connect-VIServer outputs server information. Just send it to $null when you don't need it:

Connect-VIServer | $null

Reply
0 Kudos
THaus
Contributor
Contributor
Jump to solution

You can see for the first the virtual machines node carries the inheritance and shows the -Server $global:VIServer.

The Identical node that I created doesn't have the inheritance and -Server $global:VIServer is missing

#region ****************************** Execute started - TreeNode: Virtual Machines ******************************

Get-VM -Server $global:VIServer

#endregion ****************************** Execute stopped - TreeNode: Virtual Machines ******************************

#region ****************************** Execute started - TreeNode: Problem Node ******************************

Get-VM

ERROR: 9/26/2008 9:38:46 AM Get-VM You are not currently connected to any servers. Please connect first using Connect-VIServer or one of its aliases.

#endregion ****************************** Execute completed - TreeNode: Problem Node ******************************

Reply
0 Kudos
DSotnikov
Enthusiast
Enthusiast
Jump to solution

Tedd,

This is easy to fix:

  1. Right-click your node, and click Properties on the shortcut menu.

  2. Scroll down to the Server parameter.

  3. Type the following into the value box next to it: $global:VIServer

  4. Click OK to save the changes.

Sorry that you have to do this, but unfortunately this is the way current version of VI cmdlets work with the VI Server connections set up in PowerShell functions.

Dmitry

Reply
0 Kudos
THaus
Contributor
Contributor
Jump to solution

That will work for the node but what about the script node?

Also, this just started happening, all these scripts used to carry the inheritance.

What could have happened to powergui?

I've had powergui open the entire time since initially setting up.

When I had to logout/login did I lose something to start causing this?

It seems strange that the $global:VIServer is there for what was in the powerpack but for whatever reason is no longer inherited for whatever is created outside that.

Reply
0 Kudos
DSotnikov
Enthusiast
Enthusiast
Jump to solution

For script nodes to work you would need to either:

  • start PowerGUI as VI Client plugin, or

  • add Connect-VI-Server to your PowerShell profile, or

  • add the -Server $global:VIServer to your scripts.

My guess is that scripts could have worked before because the tool was started from VI Client Plugins menu.

The issue is really with VI cmdlets and the way the connection is handled. When you connect from PowerGUI itself the connection is made from the corresponding Connect action which is a PowerShell function. For some reason, when you connect to VI Server from a function this connection is not always available for other functions, unless you use that-Server parameter. This is a bit weird and I hope someone from VMware can chime in.

Reply
0 Kudos
THaus
Contributor
Contributor
Jump to solution

Dmitry you are a genius. This is why I posted a newbie question. I has this thing running for so long that I had forgoten it was originally launched out of the plugin. All works like a champ now.

Reply
0 Kudos
DSotnikov
Enthusiast
Enthusiast
Jump to solution

Glad that I could help! Smiley Happy

Dmitry

See also: Dmitry's PowerBlog at http://dmitrysotnikov.wordpress.com

Reply
0 Kudos