Page 1 of 1

Assigning Variables to Items in Combo Box

Posted: Mon Sep 30, 2013 3:21 pm
by bzowky
Good Afternoon All -

I'm trying to create a GUI which will allow techs to deploy applications via SCCM 2012 without using the console. I'm ~90% there, but just need to figure something out. Even though I have much experience with SCCM, I don't as much with Powershell so apologies if this is a newb question :).

My GUI consists of 3 separate things.
1. Enter a hostname (textbox)
2. Select an Application (Combobox with ~12 items)
3. Click "Deploy" (button)

This is what happens on the backend:
When the user clicks the "Deploy" button, the function below is run:

Code: Select all

Set-Location A00:
Add-CMDeviceCollectionDirectMembershipRule -CollectionId $CollectionID -ResourceId $(get-cmdevice -name $txtComputerName).ResourceID
The function uses the hostname entered in step one via variable $txtComputerName, as well as the variable $CollectionID which is a list of collections named after applications - with the same application it's named for pre-advertised to it. A collection ID format example is A0000035.

The issue I'm having is that I can't get the variables set for whichever combobox item is selected. Every time I try then test the script, I get: "Add-CMDeviceCollectionDirectMembershipRule : Cannot validate argument on parameter 'CollectionId'. The argument is null or empty. Supply an argument that
is not null or empty and then try the command again."

I first tried radio buttons (1 per application) and used the code below, but it didn't work either as I got the same error above - but - I like the combo box better anyways.

Code: Select all

If ($radioButton1.checked) {
$CollectionID="A0000035"
}
elseif ($radioButton2.checked)
{
$CollectionID="A0000034"
}
Other Minor Questions
- The script would rely on ConfigurationManager.ps1 (cmdlet) to be imported before it worked per machine. Can that be added to occur during launch of the app? The file isn't local to most machines this GUI will be used on but can be copied if need be. It is on the same server as the A00: drive, thoug, if that makes a difference.
- The command above is really two commands - the first to change the drive letter to A00: and the second to add the device. Is that the best way to do it or no?

Thanks for your help!

Re: Assigning Variables to Items in Combo Box

Posted: Mon Sep 30, 2013 4:48 pm
by davidc
You need the use the textbox's Text property:
PowerShell Code
Double-click the code block to select all.
$txtComputerName.Text
These articles may be of assistance:

http://www.sapien.com/blog/2011/06/13/p ... x-control/

http://www.sapien.com/blog/2011/06/21/p ... x-control/

David

Re: Assigning Variables to Items in Combo Box

Posted: Mon Sep 30, 2013 4:55 pm
by jvierra
David lost the $ in the example

$txtComputerName.Text

YOU can also assign values to radio buttons and read them back on an event. This allows us to make updates to only the UI and the code will pick up the correct value.

Re: Assigning Variables to Items in Combo Box

Posted: Mon Sep 30, 2013 5:01 pm
by davidc
Thank you for catching that.

David

Re: Assigning Variables to Items in Combo Box

Posted: Mon Sep 30, 2013 5:12 pm
by jvierra
Here is a simple demo of how radio buttons can be used.

Attached

Re: Assigning Variables to Items in Combo Box

Posted: Mon Sep 30, 2013 5:14 pm
by jvierra
davidc wrote:Thank you for catching that.

David
Don't you ever go home? It is getting very late - you are getting very sleepy. Sleep, sleep, sleep.