Automation

 View Only
  • 1.  PowerShell to show all windows devices in vSphere

    Posted Feb 11, 2022 07:13 PM

    I have been using PowerShell in vSphere for a short couple months. Using my Win10 machine I run PowerShell script: 

    Connect-VIServer [domain name of vSphere]

    Then I use the script, which list out all the Windows Servers and Linux: 
    Get-vm | Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}}

     

     

     



  • 2.  RE: PowerShell to show all windows devices in vSphere

    Posted Feb 11, 2022 07:40 PM

    Is there a question in here?



  • 3.  RE: PowerShell to show all windows devices in vSphere

    Posted Feb 11, 2022 09:31 PM

     Yes, Thanks: There was intended to be a question written in that post. Must have been multi tasking.
    The question is could I get assistance providing the correct way to query in PowerShell all windows servers while I am logging into vSphere?



  • 4.  RE: PowerShell to show all windows devices in vSphere

    Posted Feb 11, 2022 09:40 PM

    Still not sure what the actual question is.
    Do you want to list all VMs that have a Windows Guest OS running?
    Do you have VMware Tools installed on all your VMs?



  • 5.  RE: PowerShell to show all windows devices in vSphere

    Posted Feb 11, 2022 09:46 PM

     Yes, I have VM tools installed.
    Yes, I would to list out all VMs that have Windows Guest OS Running along with their powered state. Additionally, I was curious to know if I can just flip the verbiage in the same command and list out all the Linux machines. 

    Long term, I am wanting to Log into vSphere and find out what systems are running: (servers or desktops) and run weekly updates.

    Thanks 



  • 6.  RE: PowerShell to show all windows devices in vSphere

    Posted Feb 12, 2022 06:33 AM

    You can list the Guest OS with

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

    To filter for Windows or Linux, you could do one of the following

    Get-VM |
    where{$_.ExtensionData.Summary.Config.GuestFullName -like "*Windows*"} |
    Select Name
    

    or

    Get-VM |
    where{$_.ExtensionData.Summary.Config.GuestFullName -like "*Linux*"} |
    Select Name
    


  • 7.  RE: PowerShell to show all windows devices in vSphere

    Posted Feb 15, 2022 02:56 PM

     Thank-You for script assistance. 

    I attempted to recreate the script to answer my needs of outputting: VMName, VMHost(IP), PowerState, GuestOS/runningOS) from my vSphere environment. The script works with no errors.

    However it fails on two points, "It did not filter for Windows or Linux" and "It did not provide the Guest OS name; Windows Server or Ubuntu" It shows False/True ----

    Why??? What did I Miss ???

    Get-VM | Select @{Label = "VM Name" ; Expression = {$_.Name} },VMHost, PowerState, @{Label = "Guest OS" ; Expression = {$_.ExtensionData.Summary.Config.GuestFullName -like "*Windows*"} }|
    Export-CSV -Path 'C:\users\username\documents\VMPowerOS.csv' -NoTypeInformation



  • 8.  RE: PowerShell to show all windows devices in vSphere

    Posted Feb 15, 2022 03:04 PM

    The Expression for that calculated property (Guest OS) will result in $true or $false, not the name of the Guest OS.
    Move the Where-clause

    Get-VM |
    Where-Object { $_.ExtensionData.Summary.Config.GuestFullName -like "*Windows*" } |
    Select @{Label = "VM Name" ; Expression = {$_.Name} },
        VMHost, PowerState, 
        @{Label = "Guest OS" ; Expression = {$_.ExtensionData.Summary.Config.GuestFullName} }|
    Export-CSV -Path 'C:\users\username\documents\VMPowerOS.csv' -NoTypeInformation

      



  • 9.  RE: PowerShell to show all windows devices in vSphere

    Posted Feb 15, 2022 04:18 PM

     Thank-You that worked