TomasCorey
Enthusiast
Enthusiast

get windows edition from powercli

Jump to solution

Hello,

         I'm trying to get the Windows Edition from Powercli but I can't. Searching I found this: 

$WindowsVMS = get-view -viewtype virtualmachine -property 'name','guest.guestFamily' -filter @{'guest.GuestFamily'='windowsGuest'}
$credential = get-credential

foreach ($vm in $WindowsVMS){

$vm | select name, @{n='Edition';e={(Invoke-VMScript -GuestCredential $credential -ScriptType 'powershell' -ScriptText '(gwmi win32_operatingsystem).caption' -VM $vm.name).ScriptOutput} }

}

TomasCorey_0-1611768178403.png

I try with sysinfo, regedit but I can't.

Any help is appreciated.

Thanks

Tomás

 

 

 

0 Kudos
1 Solution

Accepted Solutions
TomasCorey
Enthusiast
Enthusiast

Hello LucD,

                I was able to extract with VMware vSphere PowerCLI 5.5 Release 1. I don't know why, but I could.

TomasCorey_3-1612809011961.png


Thanks for your help.
Tomás

View solution in original post

0 Kudos
16 Replies
scott28tt
VMware Employee
VMware Employee

@TomasCorey 

Moderator: Moved to PowerCLI Discussions


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

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
LucD
Leadership
Leadership

Works for me on all the WIndows VMs where the VMware Tools are installed and where I entered the correct credentials.

Any error messages?


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

0 Kudos
TomasCorey
Enthusiast
Enthusiast

Hello, yes! I use an domain admin with admin on vcenter.

No errors... Only blank output.


Thanks

Tomás

0 Kudos
LucD
Leadership
Leadership

Are the VMware Tools installed?
Are the VMs powered on?


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

0 Kudos
TomasCorey
Enthusiast
Enthusiast

Hi LucD,

Yes and yes. My coworker runs the same script with the same user and it works.
Maybe an incompatible version of powershell and powercli?

Powershell:

PS C:\Windows\system32> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  610

 

PowerCli:

PS C:\Windows\system32> Get-PowerCLIVersion
WARNING: The cmdlet "Get-PowerCLIVersion" is deprecated. Please use the 'Get-Module' cmdlet instead.

PowerCLI Version
----------------
   VMware PowerCLI 12.1.0 build 17009493
---------------
Component Versions
---------------
   VMware Common PowerCLI Component 12.1 build 16997174
   VMware Cis Core PowerCLI Component PowerCLI Component 12.1 build 16997582
   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.1 build 16997984


PS C:\Windows\system32> Get-Module -Name VMware.* | Select-Object -Property Name,Version

Name                          Version
----                          -------
VMware.Vim                    7.0.1.16997275
VMware.VimAutomation.Cis.Core 12.1.0.16997582
VMware.VimAutomation.Common   12.1.0.16997174
VMware.VimAutomation.Core     12.1.0.16997984
VMware.VimAutomation.Sdk      12.1.0.16997004

 

Honestly, I don't know.


Thanks

Tomás

 

0 Kudos
LucD
Leadership
Leadership

Since it works for your colleague, it must be something on your station.

Did you try, with your account, from another station?
If you just run the Invoke-VMScript against a specific VM, are there any error messages?


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

0 Kudos
TomasCorey
Enthusiast
Enthusiast

LucD, 

Yes I tried but it is the same result.

Instead of pulling this report from PowerShell connected to vCenter.
Is there a way to extract from the host?

 

Regards,
Tomás

0 Kudos
LucD
Leadership
Leadership

Was that on the same station that it works for your colleague?
Do your accounts have different Roles?

Not sure what you mean by "extract from host"


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

0 Kudos
TomasCorey
Enthusiast
Enthusiast

LucD,

         No, we have the same role.

Commands from host (vim-cmd, etc.) or use command line instead of powershell.


Thanks

Tomás

0 Kudos
LucD
Leadership
Leadership

Was that on the same station?

The reason for asking, te Invoke-VMScript uses a connection over port 902 to the ESXi node where the VM is running.
It could be that this port 902 to the ESXi node is not open.

You could add the Verbose switch on the Invoke-VMScript cmdlet to see if that provides extra information.
Or you could try my Invoke-VMScriptPlus function, which provides more feedback.

You could try using Get-WmiObject with the ComputerName parameter.
If Remote Management is set up correctly, that should return the information to the calling station.


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

TomasCorey
Enthusiast
Enthusiast

Hello,

           Sorry for the delayed response.
I tryied with Invoke-VMScriptPlus but eh same result.

 

TomasCorey_0-1612807646655.png

The port 902 are open in all hosts.


Thanks 
Tomás

0 Kudos
TomasCorey
Enthusiast
Enthusiast

Hello LucD,

                I was able to extract with VMware vSphere PowerCLI 5.5 Release 1. I don't know why, but I could.

TomasCorey_3-1612809011961.png


Thanks for your help.
Tomás

0 Kudos
RThornburg
Contributor
Contributor

Do either of these work for you. I have used both and found they get the OS that the tools report to vsphere.

Get-VM  | Select Name,@{N='Guest OS';E={($_.GuestOS).trimstart("Microsoft ").trimend(" (64-bit)")}}

Get-VM  | Select Name,@{N='Guest OS';E={$_.ExtensionData.Config.GuestFullName}}

And they they do work then you could tie that to a New-VIProperty like this:

New-VIProperty -ObjectType VirtualMachine -Name GuestOS -ValueFromExtensionProperty 'Config.GuestFullName' -Force | Out-Null

Then you only need to do:

Get-VM  | Select Name,GuestOS

TomasCorey
Enthusiast
Enthusiast

Hello RThornburg,

Thanks for your reply. These scripts work but it is not what I need.
Because the operating system information is pulled from the virtual machine configuration in vMware, but I need this information to be obtained through vmtools. "ask the operating system to tell me exactly the operating system and version", for example: Windows Server 2012 R2: Standard Edition.


Thanks and Regards
Tomás

0 Kudos
LucD
Leadership
Leadership

You replied earlier that you were able to extract the required info with an older PowerCLI version.
Is there still a question open?


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

0 Kudos
TomasCorey
Enthusiast
Enthusiast

Hello LucD,

                 Not, we can close.

 

Tomas

0 Kudos