VMware Cloud Community
KarthikeyanRam1
Contributor
Contributor

VMtools and Harware report

hi,

example:

PowerCLI C:\> get-vm -name ARE01-PRT-001

get-vm : 9/13/2017 8:46:20 PM    Get-VM        VM with name 'ARE01-PRT-001'

was not found using the specified filter(s).

At line:1 char:1

+ get-vm -name ARN01-PRT-001

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (:) [Get-VM], VimException

    + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA

   utomation.ViCore.Cmdlets.Commands.GetVM

PowerCLI C:\> get-vm -name ARE01-PRT-001.TEST.corp

Name                 PowerState Num CPUs MemoryGB

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

ARN01-PRT-001.TEST... PoweredOn  2        4.000

I need a help in vmtools and hardware report,'

I have list of vms with  with half of fqdn.

$vmlist contains vms with half of fqdn. But In vcenter i have few vms with fully qualified domain name and few vms with half of fqdn.

please make the below script to get all vms that matches the name in $vmlist (contains half of fqdn) and vms in vcentre (vms with fully qualified domain name and few vms with half of fqdn.)

$vCenterServerName = "vc1" ,  "vc2" , "vc3"

foreach($vcenter in $vCenterServerName){

connect-viserver -server $vcenter

$vmlist = Get-Content -Path C:\Users\admkraman\Desktop\keyan\vmlist.txt

$objects = @()

foreach($vm in Get-VM -Name $vmlist ){

                     $obj = "" | select vCenter , vmname , Powerstate ,  HardwareVersion , HostVersion , VMToolsStatus , VMToolsVersion , VMToolsVersionStatus , VMToolsRunningStatus

                     $obj.vCenter = $vcenter

                     $obj.vmname = $vm.Name

                     $obj.Powerstate = $vm.Powerstate

                     $obj.HardwareVersion = $vm.Version

                     $obj.HostVersion = $vm.VMHost.Version

                     $obj.VMToolsStatus = $vm.ExtensionData.Guest.ToolsStatus

                     $obj.VMToolsVersion = $vm.ExtensionData.Guest.ToolsVersion

                     $obj.VMToolsVersionStatus = $vm.ExtensionData.Guest.ToolsVersionStatus

                     $obj.VMToolsRunningStatus = $vm.ExtensionData.Guest.ToolsRunningStatus

                     $objects += $obj

                     }  $objects | Export-Csv -Append  -Path "C:\Users\admkraman\Desktop\keyan\toolreport.csv"

                        disconnect-viserver -server $vcenter -Confirm:$false

                        }

0 Kudos
5 Replies
LucD
Leadership
Leadership

If you don't have VMs with the same hostname in different domains, you could do something like this.

It extracts the hostname (first qualifier), and then adds a meta-character ('*') to match all Displaynames that start with that hostname.

$vCenterServerName = "vc1" ,  "vc2" , "vc3"

foreach($vcenter in $vCenterServerName){

    Connect-VIServer -server $vcenter

    $vmlist = Get-Content -Path C:\Users\admkraman\Desktop\keyan\vmlist.txt | %{

        "$((Select -ExpandProperty Name).Split('.')[0])*"

    }

    $objects = @()

    foreach($vm in Get-VM -Name $vmlist ){

        $obj = "" | select vCenter , vmname , Powerstate ,  HardwareVersion , HostVersion , VMToolsStatus , VMToolsVersion , VMToolsVersionStatus , VMToolsRunningStatus

        $obj.vCenter = $vcenter

        $obj.vmname = $vm.Name

        $obj.Powerstate = $vm.Powerstate

        $obj.HardwareVersion = $vm.Version

        $obj.HostVersion = $vm.VMHost.Version

        $obj.VMToolsStatus = $vm.ExtensionData.Guest.ToolsStatus

        $obj.VMToolsVersion = $vm.ExtensionData.Guest.ToolsVersion

        $obj.VMToolsVersionStatus = $vm.ExtensionData.Guest.ToolsVersionStatus

        $obj.VMToolsRunningStatus = $vm.ExtensionData.Guest.ToolsRunningStatus

        $objects += $obj

    } 

    $objects | Export-Csv -Append  -Path "C:\Users\admkraman\Desktop\keyan\toolreport.csv"

    Disconnect-VIServer -server $vcenter -Confirm:$false

}


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

0 Kudos
KarthikeyanRam1
Contributor
Contributor

Hi Lucid,

In VMlist I have the first qualifier only. but in Vcenter, I have few VMs with first qualifier as well as few VMs with FQDN.

I wanted like this lucid Vms in vcenter -contains VMlist.

Please help

0 Kudos
LucD
Leadership
Leadership

Not sure what you are asking I'm afraid.

Perhaps some screenshots and the desired output of the script would help.


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

0 Kudos
KarthikeyanRam1
Contributor
Contributor

Lucid,

sorry to make it more complicated.

I need a simple script that should COMPARE the Vms in the text file(vmlist) with the Vms in the vcentre server (before the first dot the name should be same) and export the names that match in a text file

VMlist file:

fil01-map-001.test.corp

fil01-map-002

fil01-map-003

Vcentre:

fil01-map-001.test.corp

fil01-map-002.test.corp

fil01-map-003

Output file:

fil01-map-001.test.corp

fil01-map-002.test.corp

fil01-map-003

0 Kudos
LucD
Leadership
Leadership

You mean something like this?

$vCenterServerName = "vc1" ,  "vc2" , "vc3"

$vmlist = Get-Content -Path .\vmlist.txt | %{

    $_.Split('.')[0]

}

$names = @()

foreach($vcenter in $vCenterServerName){

    Connect-VIServer -server $vcenter

    $names += Get-VM | where{$vmlist -contains $_.Name.Split('.')[0]} | select -ExpandProperty Name

    Disconnect-VIServer -server $vcenter -Confirm:$false

}

$names | Set-Content -PassThru .\report.txt


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

0 Kudos