XAML GUI to Powershell with variables
<p>A fellow member on Superuser got me onto <a href="https://foxdeploy.com/2015/04/10/part-i-creating-powershell-guis-in-minutes-using-visual-studio-a-new-hope/" rel="nofollow">this guide</a> on creating a GUI to a powershell script however I am new to this area so I need a little guidance on the coding.</p>

<p>This is the XAML code generated by Visual Studio 2015;</p>

<pre><code>&lt;Window x:Name="Title" x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApplication1"
    mc:Ignorable="d"
    Title="New Mailbox" Height="400" Width="420"&gt;
&lt;Grid&gt;
    &lt;Image x:Name="image" HorizontalAlignment="Left" Height="100" Margin="14,10,0,0" VerticalAlignment="Top" Width="386" Source="C:\Users\Daniel Neocleous\Documents\Visual Studio 2015\Projects\WpfApplication1\WpfApplication1\Images\SibelcoLogo.png"/&gt;
    &lt;RadioButton x:Name="radioButton" Content="Step 1" HorizontalAlignment="Left" Margin="150,125,0,0" VerticalAlignment="Top"/&gt;
    &lt;RadioButton x:Name="radioButton_Copy" Content="Step 2" HorizontalAlignment="Left" Margin="217,125,0,0" VerticalAlignment="Top"/&gt;
    &lt;Button x:Name="button" Content="Create Mailbox" HorizontalAlignment="Left" Margin="150,152,0,0" VerticalAlignment="Top" Width="119" Height="35"/&gt;
    &lt;GroupBox x:Name="groupBox" Header="Output" HorizontalAlignment="Left" Height="169" Margin="10,192,0,0" VerticalAlignment="Top" Width="394"&gt;
        &lt;TextBox x:Name="textBox" HorizontalAlignment="Left" Height="147" Margin="0,0,-1.143,-0.714" TextWrapping="Wrap" VerticalAlignment="Top" Width="384"/&gt;
    &lt;/GroupBox&gt;

&lt;/Grid&gt;
</code></pre>

<p></p>

<p>Now from what I have understood I have to modify this code by removing the x's and the <code>x:Class="WpfApplication1.MainWindow"</code> string and add the following to the end;</p>

<pre><code>#Read XAML
    $reader=(New-Object System.Xml.XmlNodeReader $xaml) 
    try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
    catch{Write-Host "Unable to load Windows.Markup.XamlReader. Some possible causes for this problem include: .NET Framework is missing PowerShell must be launched with PowerShell -sta, invalid XAML code was encountered."; exit}
    #===========================================================================
    # Store Form Objects In PowerShell
    #===========================================================================
    $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)}
    #===========================================================================
    # Shows the form
    #===========================================================================
    $Form.ShowDialog() | out-null
</code></pre>

<p>I am a little stuck from here though assuming what I have out above is correct. How do I tie all this to the Gui? </p>

<p><a href="http://i.stack.imgur.com/ISMrd.png" rel="nofollow">GUI</a></p>

<p>There are two Radio buttons and depending which one is selected I want a different script to run and the Powershell output to be displayed in the text box at the bottom but how can I accomplish this?</p>

<p>The Powershell I want to run on Step 1</p>

<pre><code>$credentials = get-credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri URL -Credential $credentials –AllowRedirection
Import-PSSession $Session
set-ADServerSettings -ViewEntireForest $true
Enable-RemoteMailbox -Identity test@test.com -RemoteRoutingAddress test@test.com.onmicrosoft.com
Enable-RemoteMailbox -Identity test@test.com -Archive
</code></pre>

<p>Step 2</p>

<pre><code>$msolcred = get-credential
connect-msolservice -credential $msolcred
Set-MsolUser -UserPrincipalName test@test.com -UsageLocation GB
$LicOpt = New-MsolLicenseOptions -AccountSkuId company:STANDARDPACK -DisabledPlans MCOSTANDARD
Set-MsolUserLicense -UserPrincipalName test@test.com -AddLicenses company:STANDARDPACK -LicenseOptions $LicOpt
Remove-PSSession $Session
</code></pre>

<p>Thanks for the advice guys.</p>