VMware Cloud Community
EMCDD11
Contributor
Contributor

How to grab output from PowerCLI command

Hi , I have some requirements to execute some commands in PowerCLI for VxRail and I have to parse some information for further processing.

I want to do it in Java, please help me about how to execute a command using java for VMware PowerCLI  and to capture the output in InputStream as we do in normal java programs.

To be more specific, I want to execute a simple command like get-powercliversion in PowerCLI.

I get the following output.

PowerCLI C:\> get-powercliversion

PowerCLI Version

----------------

   VMware PowerCLI 6.5 Release 1 build 4624819

---------------

Component Versions

---------------

   VMware Cis Core PowerCLI Component 6.5 build 4624453

   VMware VimAutomation Core PowerCLI Component 6.5 build 4624450

   VMWare ImageBuilder PowerCLI Component 6.5 build 4561891

   VMWare AutoDeploy PowerCLI Component 6.5 build 4561891

   VMware Vds PowerCLI Component 6.5 build 4624695

   VMware Cloud PowerCLI Component 6.5 build 4624821

   VMware HA PowerCLI Component 6.0 build 4525225

   VMware HorizonView PowerCLI Component 7.0.2 build 4596620

   VMware Licensing PowerCLI Component 6.5 build 4624822

   VMware PCloud PowerCLI Component 6.5 build 4624825

   VMware Storage PowerCLI Component 6.5 build 4624820

   VMware vROps PowerCLI Component 6.5 build 4624824

   VMware vSphere Update Manager PowerCLI 6.5 build 4540462

PowerCLI C:\>

​My task in Java will be to parse and to get the version info.

Tags (3)
Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership

There are many routes to go from point A to point B.
But capturing PowerShell output to parse it then in java is definitely not a straight line :smileygrin:

You can use for example the following to get the PowerCLI modules and their version.

Get-Module -Name VMware* -ListAvailable | Select Name, Version

Whatever format you want for the output, you can most probably do that natively in PowerShell.

If you prefer a CSV format, just do

Get-Module -Name VMware* -ListAvailable | Select Name, Version |

   ConvertTo-Csv -NoTypeInformation -UseCulture

We even have to possibility to write to a file in PowerShell, and that in many formats.

Btw, your PowerCLI version is quite old, time to upgrade.


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

Reply
0 Kudos
EMCDD11
Contributor
Contributor

Hi Lucd,

Thanks for quick jump, I have already installed PowerCLi in my windows machine, but when I execute using PowerShell (Not PowerCli), it says command is not recognized.

If I am able to execute PowerCli using PowerShell, then I can do something.

By the way could you tell me where the exe for PowerCLI is located in windows machine.

I am still in Route A, unable to move ahead :smileylaugh:.

Reply
0 Kudos
EMCDD11
Contributor
Contributor

Hi Experts,

I am getting the following error. Please help me.

get-powercliversion : The term 'get-powercliversion' is not recognized as the name of a cmdlet, function, script file,

or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and

try again.

Reply
0 Kudos
LucD
Leadership
Leadership

PowerCLI is a kind of layer on top of PowerShell.
Since quite some time that PowerCLI layer comes in the form of modules.

These modules are installed from the PowerShell Gallery.
See Welcome PowerCLI to the PowerShell Gallery – Install Process Updates on how to replace your older MSI-based installation with a recent version from the Gallery.

There is no EXE to "start" PowerCLI, the PowerShell exe loads the required PowerCLI modules for you.

If you are just starting your PowerShell and PowerCLI trip, I would advise to learn some basic concepts.
Slightly outdated, but some pages I still consider very valuable to get acquainted with PowerShell and PowerCLI are these 2 blog posts from CrazyConsultant:

PowerShell study guide – core concepts

PowerCLI study guide – core concepts

Invest some time in exploring PowerShell/PowerCLI, it will be worth your while.
Heck, you might not even want to go back to java anymore :smileygrin:


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

Reply
0 Kudos
EMCDD11
Contributor
Contributor

Hi Lucd,

I have already followed the link and I am able to execute the command (get-powercliversion) in PowerShell (Not PowerCLI), I am getting the response. But I am unable to handle in Java.

I am not able to grab the output.

Besides, when I execute the command, I get the following output.

PS C:\Users\mishrd5> get-powercliversion

WARNING: The cmdlet "Get-PowerCLIVersion" is deprecated. Please use the 'Get-Module' cmdlet instead.

PowerCLI Version

----------------

   VMware PowerCLI 11.0.0 build 10380590

---------------

Component Versions

---------------

   VMware Cis Core PowerCLI Component PowerCLI Component 11.0 build 10335701

   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.0 build 10336080

Could you please help me to get the actual command PowerCli version ?

My next task is to do something for java.

Reply
0 Kudos
LucD
Leadership
Leadership

Try the line I gave earlier with the Get-Module cmdlet.


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

Reply
0 Kudos
LucD
Leadership
Leadership

You might want to try what is described in Invoke PowerShell scripts from Java.


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

Reply
0 Kudos