none
MenuStrip and a Question about Class win32_product RRS feed

  • Question

  • Hello,

    I have a bunch of questions I'm hoping someone can answer.

    1.) I would like to add a menu separator and a checkbox under a dropdownitem for a toolstripmenuitem

         Similar to what you would see in ISE or Internet Explorer.

         I then need to pass the state of this checkbox into a function

    2.) I have created a file menu item and would like to create a separator and then add a list of MRU items restricted to only displaying the five previous opened config files.

    3.) Can someone propose an alternative to using the get-wmiobject win32_Product class

    The below function I wrote to get the Product Version for some VMware products, but it is slow making the initial connection.   Looking at the Uninstall registry key won't work because it doesn't contain the product version.

    I know it looks odd.  I could not find a good way to detect which servers the products were installed on.   So instead I pass the servers that would host these products based on our build standards.

    Function get-version($vcenter,$sso,$vum,$credentials) {
    
        Write-Host "Getting Version information. This usually takes awhile. Be Patient  " -NoNewline
        
        $Roles  = "VMware vCenter Server","VMware vCenter Inventory Service","VMware vSphere Web Client","vCenter Single Sign On","VMware vSphere Update Manager","vSphere Syslog Collector"
    
        $i = 0
        $output = @()
        $Servers = "$vcenter","$vcenter","$vcenter","$sso","$vum","$vum"
        $ErrorActionPreference = 'silentlycontinue'
    
        ForEach ($input in $Servers) {
    
            IF ($psversiontable.psversion.major -ge 3) { Write-Progress -activity "Getting Version Information - Takes awhile.  Be Patient." -status $Roles[$i] -PercentComplete (($i / $roles.Length)  * 100) } Else { ticker }
               
            $object = New-Object PSObject
            $object | Add-Member NoteProperty "Role"       $Roles[$i]
            $object | Add-Member NoteProperty "Hostname"   $Servers[$i]
            $object | Add-Member NoteProperty "IP Address" (Get-WmiObject Win32_networkadapterconfiguration -ComputerName $Servers[$i] -Credential $credentials | ? {$_.IPEnabled} | Select-Object IPaddress).IPaddress[0]
            $object | Add-Member NoteProperty "Version"    (Get-WmiObject win32_Product -ComputerName $Servers[$i] -Credential $credentials | Where-Object {$_.Name -eq $Roles[$i]}).version
    
            $output += $object
            $i++
        }
    
        IF ($PSVersionTable.PSVersion.Major -ge 3) { Write-Progress -activity "Completed Getting Version Information" -Completed } Else { write-host "...Done!" -NoNewline }
        write-host ""
        $output
    
    } # End Function get-Version


    Walter

    Saturday, February 1, 2014 11:54 PM

Answers

  • This is what it appears you are trying to do.

    $filter=@"
         Name'VMware' 
         OR Name='vCenter Server'
         OR Name='VMware vCenter Inventory Service'
         OR Name='VMware vSphere Web Client'
         OR Name='vCenter Single Sign On'
         OR Name='VMware vSphere Update Manager'
         OR Name='vSphere Syslog Collector'
    "@
    
    Get-WmiObject win32_Product -ComputerName $vcenter,$sso,$vum -Credential $credentials -Filter $filter |
         ForEach-Object{
            $IPAddress=(test-connection $_.__Server -count 1).IPV4Address.IPAddressToString
            $_|Add-Member NoteProperty Version $IPAddress -PassThru
        } |
        Format-Table -Properties __SERVER,Name,IPAddress,Version -Auto
    

    PowerShell is designed to do ll of these things for us.  YOu are ignoring how PowerShell and WMI work and trying to do something that would be done in a batch file of VBScript. That will be very slow.

    If you have more than a few servers then we can use concurrent jobs to speed things up.


    ¯\_(ツ)_/¯

    • Marked as answer by Walter Beach Sunday, February 2, 2014 4:13 AM
    Sunday, February 2, 2014 12:42 AM

All replies

  • Your code doesn't relay make much sense.

    What is this line for:

    $Servers = "$vcenter","$vcenter","$vcenter","$sso","$vum","$vum"

    Funtion get-version($vcenter,$sso,$vum,$credentials

    Why are you using credentials.  Only and admin can call remotely?

    Are you trying to get all of these roles? Aren't these produces?

    $Roles  = "VMware vCenter Server","VMware vCenter Inventory Service","VMware vSphere Web Client","vCenter Single Sign On","VMware vSphere Update Manager","vSphere Syslog Collector"


    ¯\_(ツ)_/¯

    Sunday, February 2, 2014 12:15 AM
  • This will get you everything much faster. you are making repeated round trips and returning everything from the remote servers.  That is not how we use WMI.

    try this and you will see that it is much faster.

    $filter=@"
         Name'VMware' 
         OR Name='vCenter Server'
         OR Name='VMware vCenter Inventory Service'
         OR Name='VMware vSphere Web Client'
         OR Name='vCenter Single Sign On'
         OR Name='VMware vSphere Update Manager'
         OR Name='vSphere Syslog Collector'
    "@
    
    Get-WmiObject win32_Product -ComputerName $vcenter,$sso,$vum -Credential $credentials -Filter $filter |
         Select Name, __SERVER, Version
    
    


    ¯\_(ツ)_/¯


    • Edited by jrv Sunday, February 2, 2014 12:33 AM
    Sunday, February 2, 2014 12:32 AM
  • This is what it appears you are trying to do.

    $filter=@"
         Name'VMware' 
         OR Name='vCenter Server'
         OR Name='VMware vCenter Inventory Service'
         OR Name='VMware vSphere Web Client'
         OR Name='vCenter Single Sign On'
         OR Name='VMware vSphere Update Manager'
         OR Name='vSphere Syslog Collector'
    "@
    
    Get-WmiObject win32_Product -ComputerName $vcenter,$sso,$vum -Credential $credentials -Filter $filter |
         ForEach-Object{
            $IPAddress=(test-connection $_.__Server -count 1).IPV4Address.IPAddressToString
            $_|Add-Member NoteProperty Version $IPAddress -PassThru
        } |
        Format-Table -Properties __SERVER,Name,IPAddress,Version -Auto
    

    PowerShell is designed to do ll of these things for us.  YOu are ignoring how PowerShell and WMI work and trying to do something that would be done in a batch file of VBScript. That will be very slow.

    If you have more than a few servers then we can use concurrent jobs to speed things up.


    ¯\_(ツ)_/¯

    • Marked as answer by Walter Beach Sunday, February 2, 2014 4:13 AM
    Sunday, February 2, 2014 12:42 AM
  • Now you will need to post a separate question for the menu issue.  We don't allow lists of unrelated questions.  Please read the forum guidelines.

    ¯\_(ツ)_/¯

    Sunday, February 2, 2014 12:44 AM
  • Thank you for your help.

    Not only is it faster, but it is also a lot cleaner.

    It alse helped me resolve some other issues I tried to cheat to work around.


    Walter

    Sunday, February 2, 2014 4:20 AM
  • Hi

    I can't stress enough how important it is to either take a course in PowerShell or study with a good book.  It cannot be guessed. You must learn the basics of program management and design and you must learn how PowerShell implements an object system.  PowerShell is OOP.  If you havenever had any formal training in computer science or programming you will be constantly fighting to understand what is happening.  Starting with a good book will catapult you into PowerShell ver quickly.


    ¯\_(ツ)_/¯

    Sunday, February 2, 2014 4:31 AM