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.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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
Last visit: Wed Apr 20, 2022 5:43 am

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

Post by obrienc »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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
Last visit: Wed Apr 20, 2022 5:43 am

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

Post by obrienc »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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
Last visit: Wed Apr 20, 2022 5:43 am

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

Post by obrienc »

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
Last visit: Wed Apr 20, 2022 5:43 am

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

Post by obrienc »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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
Last visit: Wed Apr 20, 2022 5:43 am

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

Post by obrienc »

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)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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.
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked