Author Posts

May 19, 2017 at 2:47 pm

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.

May 22, 2017 at 11:36 am

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

May 24, 2017 at 1:16 am

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.