Combobox and calculations

Welcome Forums General PowerShell Q&A Combobox and calculations

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 8 months ago.

  • Author
  • #71095

    Points: 1
    Rank: Member

    Hello. I am using PowerShell Studio and having an issue with calculations. I think...

    I load combobox4 which will assign memory to a virtual machine on hyper-v

    $formSpinUpVirtualMachine_Load = {
    	Load-ComboBox -ComboBox $combobox1 -Items ("Web", "App", "SQL", "Dev", "Test", "INTG", "UAT", "Load", "Prod")
    	Load-ComboBox -ComboBox $combobox2 -Items (1 .. 30)
    	Load-ComboBox -ComboBox $combobox3 -Items (1 .. 8)
    	Load-ComboBox -ComboBox $combobox4 -Items (1 .. 10)
    	$items = 1 .. 10 |
    			Name = "$_`GB"
    			Value = $_ * 1GB
    	$combobox4.DataSource = [System.Collections.ArrayList]$items
    	$combobox4.DisplayMember = 'Name'

    In my button click event I created $vmem to hold the memory amount selected from the combobox4. The dialogue shows me a value so I think that's working.

    $buttonDeploy_Click = {
    	$numproc = $combobox3.SelectedItem
    	$a = $combobox1.SelectedItem
    	$vmem = $combobox4.SelectedItem.Value
    	Write-Host $combobox4.SelectedItem.Value

    When I try to use the variable it complains that I haven't assigned a variable.

    Set-VM -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes $vmem

    The original script I wrote in the ISE I just assigned a value of 4GB and was just trying to make it a variable

    Set-VM -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes 4GB

    ERROR: Invalid minimum memory amount assigned for 'Web1' because the configured initial amount of memory assigned to this virtual machine is '512' MB. (Virtual
    ERROR: A parameter that is not valid was passed to the operation.

  • #71174

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    What does $vmem actually contain _just before_ you run Set-VM?

    • #71366

      Points: 1
      Rank: Member

      Thank you for the reply. $vmem was supposed to hold the selected value from the dropdown, 1GB 4Gb etc... i used Set-VMMemory instead of Set-VM and it worked.

The topic ‘Combobox and calculations’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort