Maintain Variable outside of a function statement

I’m looking for some help with my powershell script.
I have created a pull-down menu which holds a list servers. Upon selecting a server the script logic runs to validate the server choice.  After this has completed I cannot maintain this selection (variable) outside of the drop down function (Line 79).

I am looking for some help with this, as I would like to use the varibale further down into the script.


[array]$DropDownArray1 = get-exchangeserver |? {$_.IsE14OrLater -eq $True} |% {$}

function Return-DropDown {
		$Node1 = $DropDown.SelectedItem
		Write-Host -Fore "Green" "$Node1"
			do {
				#$Node1 = $DropDown.SelectedItem
				#Write-Host -Fore "Green" "$Node1"
				$p = (get-exchangeserver -identity $Node1).admindisplayversion
				Write-Host -Fore "Green" "$p"
				$q = (get-exchangeserver -identity $Node1).IsMailboxServer
				Write-Host -Fore "Green" "$q"
				$x = (Get-MailboxServer -identity $Node1).DatabaseAvailabilityGroup
				Write-Host -Fore "Green" "$x"
				$a = (get-exchangeserver -identity $Node1).admindisplayversion
				$b = (get-exchangeserver -identity $Node1).IsMailboxServer
				$c = (Get-MailboxServer -identity $Node1).DatabaseAvailabilityGroup
					if ($a -notmatch "14.1") {
										Write-Host -Fore "Yellow" "$Node1 is not an Exchange 2010 Server"
										$input = $true
						elseif ($b -ne $True) {
												Write-Host -Fore "Yellow" "$Node1 does not have Exchange 2010 Mailbox Server Role installed"
												$input = $True
						elseif ($c -ne $False) {
												Write-Host -Fore "Yellow" "$Node1 is already part of DAG $x"
												$input = $True
						else {
							Write-Host -Fore "Green" "$Node1 is not part of DAG"
							$input = $False
					} While ($input)
[Void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[Void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

$Form = New-Object System.Windows.Forms.Form

$Form.width = 300
$Form.height = 150
$Form.Text = ”DropDown”

$DropDown = new-object System.Windows.Forms.ComboBox
$DropDown.Location = new-object System.Drawing.Size(100,10)
$DropDown.Size = new-object System.Drawing.Size(130,30)
ForEach ($ExSrv1 in $DropDownArray1) {

$DropDownLabel = new-object System.Windows.Forms.Label
$DropDownLabel.Location = new-object System.Drawing.Size(10,10)
$DropDownLabel.size = new-object System.Drawing.Size(100,40)
$DropDownLabel.Text = "Exchange 2010 Server"

$Button = new-object System.Windows.Forms.Button
$Button.Location = new-object System.Drawing.Size(100,50)
$Button.Size = new-object System.Drawing.Size(100,30)
$Button.Text = "Select Server"

Write-Host -Fore "Green" "$Node1"

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Being a newb my self, could it be as a result of you setting the $Node1 Variable within a function?
Google variabl scopes. I think you need to set node1 as  $Global:node1 =......

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.