VMware Cloud Community
ranjitcool
Hot Shot
Hot Shot
Jump to solution

OSfullname matches

Hey Guys,

So I am writing the script - a simple one.

So far I have this.

Connect-viserver -server localhost -protocol https -user xxx -password xxx

$vms = get-vm

$numcount=0

foreach($vm in $vms)

{

if($vm.version -ne "v7")

     {

          $osverions=Get-VMGuest -vm $vm

          $strOut = "Is not a v7 virtual machine, $vm.name : $osversions.osfullname "

          $numcount+1         

     }

}

$strout = " There are a total of $numcount vms which are not v7 hardware machines "

--- Now I want to be able to display the count first before displaying the name and the osfullname of the vms. To do that I am guessing I need to put all the values in an object or an array (preferrably an object) and then later call the object variables to do so.

I apologize but how do I create an object in powercli? I am unsure, did some googleing and confused me a bit.

Please advice.

Thanks

RJ

Please award points if you find my answers helpful Thanks RJ Visit www.rjapproves.com
0 Kudos
1 Solution

Accepted Solutions
Hosted201110141
Enthusiast
Enthusiast
Jump to solution

The .ExtensionData is the same thing as get-view, which gives you acess to the SDK.  If you want to walk through the tree you can do something like:

$vm = get-vm -name "pickarealvm"

$vm.ExtensionData

This will show you everything and you can walk all the items from there by continuing the string like .extensiondata.config etc.

You can also find all these objects by going to https://yourhostorvcenter/sdk

View solution in original post

0 Kudos
8 Replies
ranjitcool
Hot Shot
Hot Shot
Jump to solution

Quick update -

I tried this script and it gives me weird answers than what I would normally expect.

First off - I am unsure why the $numcount+1 increment is displayed, should'nt it simply increment rather than output ? Is $numcount = $numcount + 1 the right way to do that?

Thanks

RJ

Please award points if you find my answers helpful Thanks RJ Visit www.rjapproves.com
0 Kudos
Hosted201110141
Enthusiast
Enthusiast
Jump to solution

Is $numcount = $numcount + 1 the right way to do that?

Yes, that would be the correct way to increment

or you could use $numcount++

0 Kudos
Hosted201110141
Enthusiast
Enthusiast
Jump to solution

I think you'll find that this will work better for you

Connect-viserver -server localhost -protocol https -user xxx -password xxx

$vms = get-vm

$numcount=0

foreach($vm in $vms)

{

if($vm.version -ne "v7")

     {


          Write-Host "Is not a v7 virtual machine, $($vm.name) : $($vm.ExtensionData.Summary.Guest.GuestFullName) "

          $numcount++      

     }

}


Write-Host " There are a total of $numcount vms which are not v7 hardware machines "

0 Kudos
ranjitcool
Hot Shot
Hot Shot
Jump to solution

Thanks for the reply.

In here - Write-Host "Is not a v7 virtual machine, $($vm.name) : $($vm.ExtensionData.Summary.Guest.GuestFullName) "

echo, write-host, strout - which one to pick to display?

Also when you say $($vm.ExtensionData.Summary.Guest.GuestFullName -  is this an alternative to get-vmhost.osfullname?

Also the output is -

Is not a v7 virtual machine, Node2i : 
Is not a v7 virtual machine, Xenserver : 
Is not a v7 virtual machine, ubuntu10 : 
Is not a v7 virtual machine, vCenter : Microsoft Windows Server 2008 R2 (64-bit)

What I am aiming to do is to check if a vm is v7 then if it is rhel5 or win2008 - with the output as vcenter: or node2i: - i am unsure how to get rid of these headings.

If os= win2008 then check for hotadd enabled or not. else report.

Thanks

Please award points if you find my answers helpful Thanks RJ Visit www.rjapproves.com
0 Kudos
Hosted201110141
Enthusiast
Enthusiast
Jump to solution

If you want the output sent to the screen you use Write-Host in powershell.

$vm.ExtensionData.Summary.Guest.GuestFullName should be a substitute for get-vmguest.osfullname.  if you are not getting any output from it I believe that means vmware tools is not installed on that VM.

I also rewrote the script a bit to get the number of VMs that are not v7 first as you requested in your first post.  I'll see what I can do about checking for hotadd

$OldVirtualMachines = @()
Get-VM | %{
    if ($_.version -ne "v7") {
        $OldVirtualMachines += $_
    }
}
Write-host " There are a total of $($OldVirtualMachines.length) vms which are not v7 hardware machines "
for ($i=0;$i -lt $OldVirtualMachines.length; $i++) {
    Write-Host "Is not a v7 virtual machine, $($OldVirtualMachines[$i].name) : $($OldVirtualMachines[$i].ExtensionData.Summary.Guest.GuestFullName) "
}

0 Kudos
Hosted201110141
Enthusiast
Enthusiast
Jump to solution

I beleive this does what you are asking for.

$OldVirtualMachines = @()
Get-VM | %{
    if ($_.version -ne "v7") {
        $OldVirtualMachines += $_
    }
}
Write-host " There are a total of $($OldVirtualMachines.length) vms which are not v7 hardware machines "
for ($i=0;$i -lt $OldVirtualMachines.length; $i++) {
    Write-Host "Is not a v7 virtual machine, $($OldVirtualMachines[$i].name) : $($OldVirtualMachines[$i].ExtensionData.Guest.GuestFullName) "
    if (($OldVirtualMachines[$i].ExtensionData.Guest.GuestFullName -like "Microsoft Windows Server 2008*") -and ($OldVirtualMachines[$i].ExtensionData.Config.CpuHotAddEnabled -eq "True")) {
        Write-Host "$($OldVirtualMachines[$i].name) has CPU Hot Add Enabled"
    }
    if (($OldVirtualMachines[$i].ExtensionData.Guest.GuestFullName -like "Microsoft Windows Server 2008*") -and ($OldVirtualMachines[$i].ExtensionData.Config.MemoryHotAddEnabled -eq "True")) {
        Write-Host "$($OldVirtualMachines[$i].name) has Memory Hot Add Enabled"
    }
}

0 Kudos
ranjitcool
Hot Shot
Hot Shot
Jump to solution

Wow, thanks a lot, this gives me much better idea.

How do i know all the possibilites of this array.exteniondata.config.xxxx  -- as in how do i know all ways to use the .extensiondata method? Please advice. Looks like using extensiondata is much nicer than calling get-vmhost ....

RJ

Please award points if you find my answers helpful Thanks RJ Visit www.rjapproves.com
0 Kudos
Hosted201110141
Enthusiast
Enthusiast
Jump to solution

The .ExtensionData is the same thing as get-view, which gives you acess to the SDK.  If you want to walk through the tree you can do something like:

$vm = get-vm -name "pickarealvm"

$vm.ExtensionData

This will show you everything and you can walk all the items from there by continuing the string like .extensiondata.config etc.

You can also find all these objects by going to https://yourhostorvcenter/sdk

0 Kudos