Automation

 View Only
Expand all | Collapse all

get windows edition from powercli

vmtraining

vmtrainingJan 27, 2021 09:35 PM

  • 1.  get windows edition from powercli

    Posted Jan 27, 2021 05:37 PM

    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

     

     

     



  • 2.  RE: get windows edition from powercli

    Broadcom Employee
    Posted Jan 27, 2021 09:35 PM

     

    Moderator: Moved to PowerCLI Discussions



  • 3.  RE: get windows edition from powercli

    Posted Jan 27, 2021 10:43 PM

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

    Any error messages?



  • 4.  RE: get windows edition from powercli

    Posted Jan 28, 2021 11:45 AM

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

    No errors... Only blank output.


    Thanks

    Tomás



  • 5.  RE: get windows edition from powercli

    Posted Jan 28, 2021 12:15 PM

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



  • 6.  RE: get windows edition from powercli

    Posted Jan 28, 2021 12:53 PM

    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

     



  • 7.  RE: get windows edition from powercli

    Posted Jan 28, 2021 12:57 PM

    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?



  • 8.  RE: get windows edition from powercli

    Posted Jan 28, 2021 01:10 PM

    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



  • 9.  RE: get windows edition from powercli

    Posted Jan 28, 2021 01:22 PM

    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"



  • 10.  RE: get windows edition from powercli

    Posted Jan 28, 2021 01:46 PM

    LucD,

             No, we have the same role.

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


    Thanks

    Tomás



  • 11.  RE: get windows edition from powercli

    Posted Jan 28, 2021 02:19 PM

    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.



  • 12.  RE: get windows edition from powercli

    Posted Feb 08, 2021 06:08 PM

    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



  • 13.  RE: get windows edition from powercli
    Best Answer

    Posted Feb 08, 2021 06:30 PM

    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



  • 14.  RE: get windows edition from powercli

    Posted Feb 12, 2021 04:15 PM

    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



  • 15.  RE: get windows edition from powercli

    Posted Feb 15, 2021 01:04 PM

    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



  • 16.  RE: get windows edition from powercli

    Posted Feb 15, 2021 01:12 PM

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



  • 17.  RE: get windows edition from powercli

    Posted Feb 15, 2021 01:24 PM

    Hello LucD,

                     Not, we can close.

     

    Tomas