Combobox and calculations

This topic contains 2 replies, has 2 voices, and was last updated by  Chris 4 months, 4 weeks ago.

  • Author
    Posts
  • #71095

    Chris
    Participant

    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 |
    	ForEach-Object{
    		[pscustomobject]@{
    			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
    	[System.Windows.Forms.MessageBox]::Show($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

    Don Jones
    Keymaster

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

    • #71366

      Chris
      Participant

      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.

You must be logged in to reply to this topic.