Combobox variable for memory set GB, MB, KB

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.
User avatar
jvierra
Posts: 11564
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Combobox variable for memory set GB, MB, KB

Post by jvierra » Thu May 18, 2017 9:05 pm

Why are you loading $combobox4 twice? Why won't you post code. Pictures are useless. How are you assigning $vmem?

Just copy and paste the code in the event using the code formatting tools.

User avatar
obrienc
Posts: 59
Joined: Mon Dec 12, 2016 10:58 am

Re: Combobox variable for memory set GB, MB, KB

Post by obrienc » Fri May 19, 2017 8:33 am

Instead of using Set-VM which works in the powershell ISE
  1. Set-VM -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes $vmem
I used
  1. Set-VMMemory -ComputerName $s1 -VMName $a$_ -DynamicMemoryEnabled $true -StartupBytes $vmem -MinimumBytes $vmem -MaximumBytes $vmem
Thanks

User avatar
jvierra
Posts: 11564
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Combobox variable for memory set GB, MB, KB

Post by jvierra » Fri May 19, 2017 8:40 am

I posted this answer twice before. Please try to understand what it is and that you MUST use it:

$vmem = $combobox4.SelectedItem.Value

User avatar
obrienc
Posts: 59
Joined: Mon Dec 12, 2016 10:58 am

Re: Combobox variable for memory set GB, MB, KB

Post by obrienc » Fri May 19, 2017 2:08 pm

I did use
  1. $vmem = $combobox4.SelectedItem.Value

It didn't work, or I should say that it is the right code but did not change the memory. Set-vm works in the ISE to change memory but not PSStudio. This is the command with memory hardcoded using set-vm done in the ISE.
  1. Set-VM -Name $a$_ -DynamicMemory -MemoryStartupBytes 4GB
When I used a different cmdlet Set-VMMemory it works. I didn't change what you posted.
Last edited by obrienc on Fri May 19, 2017 2:18 pm, edited 1 time in total.

User avatar
jvierra
Posts: 11564
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Combobox variable for memory set GB, MB, KB

Post by jvierra » Fri May 19, 2017 2:17 pm

Look at the help for the commands. Some parameters take an int32 and some int64. The limit for int32 is 1.9999Gb.

[int32]$n = 2Gb

The question was how to return values from a ComboBox. I think we have answered that. How to use the CmdLets will require you to use the help to see what the parameters require.

User avatar
obrienc
Posts: 59
Joined: Mon Dec 12, 2016 10:58 am

Re: Combobox variable for memory set GB, MB, KB

Post by obrienc » Fri May 19, 2017 2:22 pm

Please see my last I was editing when you posted. I posted how it looked in the ISE but for some reason didn't work in PSStudio. Actually, Set-Vm works when you hardcode the 4GB just not with the variable.

User avatar
obrienc
Posts: 59
Joined: Mon Dec 12, 2016 10:58 am

Re: Combobox variable for memory set GB, MB, KB

Post by obrienc » Fri May 19, 2017 2:27 pm

Works in ISE , Works in PSStudio
  1. Set-VM -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes [b]4GB[/b]
Does not work in PSStudio
  1. [b]Set-VM[/b] -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes [b]$vmem[/b]
Works in PSStudio
  1. [b]Set-VMMemory[/b] -ComputerName $s1 -VMName $a$_ -DynamicMemoryEnabled $true -StartupBytes $vmem -MinimumBytes $vmem -MaximumBytes $vmem

User avatar
jvierra
Posts: 11564
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Combobox variable for memory set GB, MB, KB

Post by jvierra » Fri May 19, 2017 2:48 pm

It works fine for me every time. Somewhere you have screwed up the code.

You asked how to get the number from the ComboBox. We did that.

$vmem = $combobox4.Selected.Item.Value

Use the debugger and check this for the correct value.

You do not really need a new variable:

Set-VM -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes ($combobox4.SelectedItem.Value)

You can also do this:

[int64]$vmem = $combobox4.Selected.Item.Value

User avatar
obrienc
Posts: 59
Joined: Mon Dec 12, 2016 10:58 am

Re: Combobox variable for memory set GB, MB, KB

Post by obrienc » Sat May 20, 2017 5:34 pm

Set-Vm doesn't work, not sure if you saw my comment above. It works in the ISE
  1. Set-VM -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes ($combobox4.SelectedItem.Value)
Set-VMMemory works
  1. Set-VMMemory -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes ($combobox4.SelectedItem.Value)

User avatar
jvierra
Posts: 11564
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Combobox variable for memory set GB, MB, KB

Post by jvierra » Sat May 20, 2017 5:42 pm

Sorry but it works for me.

Without the exact code you are suing this is all just guesswork.

Remember that the maximum for a value with Set-Vm is a 64bit int. Any double can be converted to an Int64. There is no issue. You need to run under the debugger to find out why you are getting nulls.

Locked