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.
Combobox variable for memory set GB, MB, KB
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.
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.
Re: Combobox variable for memory set GB, MB, KB
Instead of using Set-VM which works in the powershell ISE
I used
Thanks
- Set-VM -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes $vmem
- Set-VMMemory -ComputerName $s1 -VMName $a$_ -DynamicMemoryEnabled $true -StartupBytes $vmem -MinimumBytes $vmem -MaximumBytes $vmem
Re: Combobox variable for memory set GB, MB, KB
I did use
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.
When I used a different cmdlet Set-VMMemory it works. I didn't change what you posted.
- $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.
- Set-VM -Name $a$_ -DynamicMemory -MemoryStartupBytes 4GB
Last edited by obrienc on Fri May 19, 2017 2:18 pm, edited 1 time in total.
Re: Combobox variable for memory set GB, MB, KB
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.
[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.
Re: Combobox variable for memory set GB, MB, KB
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.
Re: Combobox variable for memory set GB, MB, KB
Works in ISE , Works in PSStudio
Does not work in PSStudio
Works in PSStudio
- Set-VM -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes [b]4GB[/b]
- [b]Set-VM[/b] -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes [b]$vmem[/b]
- [b]Set-VMMemory[/b] -ComputerName $s1 -VMName $a$_ -DynamicMemoryEnabled $true -StartupBytes $vmem -MinimumBytes $vmem -MaximumBytes $vmem
Re: Combobox variable for memory set GB, MB, KB
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
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
Re: Combobox variable for memory set GB, MB, KB
Set-Vm doesn't work, not sure if you saw my comment above. It works in the ISE
Set-VMMemory works
- Set-VM -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes ($combobox4.SelectedItem.Value)
- Set-VMMemory -ComputerName $s1 -Name $a$_ -DynamicMemory -MemoryMinimumBytes ($combobox4.SelectedItem.Value)
Re: Combobox variable for memory set GB, MB, KB
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.
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.