1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development XAML GUI to Powershell with variables

Discussion in 'Software' started by neocleous, 30 May 2016.

  1. neocleous

    neocleous Member

    Joined:
    12 Feb 2002
    Posts:
    656
    Likes Received:
    1
    Hi all,

    I'm new to scripting and coding but I have something that is very simple but I am struggling to wrap my head around how to link it all together.

    I want to make a GUI for two Powershell scripts and depending on which radio button is selected a different script will run.

    This is the GUI
    [​IMG]

    This is the XAML code generated by Visual Studio 2015

    <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="449.731" Width="420">
    <Grid>
    <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"/>
    <RadioButton x:Name="step1" Content="Step 1" HorizontalAlignment="Left" Margin="150,125,0,0" VerticalAlignment="Top"/>
    <RadioButton x:Name="step2" Content="Step 2" HorizontalAlignment="Left" Margin="217,125,0,0" VerticalAlignment="Top"/>
    <Button x:Name="button" Content="Create Mailbox" HorizontalAlignment="Left" Margin="150,201,0,0" VerticalAlignment="Top" Width="119" Height="35"/>
    <GroupBox x:Name="groupBox" Header="Output" HorizontalAlignment="Left" Height="169" Margin="10,243,0,0" VerticalAlignment="Top" Width="394">
    <TextBox x:Name="Outpu" HorizontalAlignment="Left" Height="147" Margin="0,0,-1.143,-0.714" TextWrapping="Wrap" VerticalAlignment="Top" Width="384"/>
    </GroupBox>
    <Label x:Name="label" Content="Email address" HorizontalAlignment="Left" Margin="73,153,0,0" VerticalAlignment="Top" Height="26"/>
    <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="156,163,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="16"/>
    <TextBox x:Name="emailentry" HorizontalAlignment="Left" Height="23" Margin="161,157,0,0" TextWrapping="Wrap" Text="Users email address" VerticalAlignment="Top" Width="191"/>

    </Grid>
    </Window>

    This is the 'Step 1' PS script

    $credentials = get-credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://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

    Step 2 PS script

    $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

    From the text entry box I need to pass the email string to the PS script as this is the only variable in the script but I don't know how to do this.

    Thanks for the help guys.
     
  2. deathtaker27

    deathtaker27 #noob

    Joined:
    17 Apr 2010
    Posts:
    2,070
    Likes Received:
    112
    I personally wouldn't look at gui frontends to scripts until you understand how powershell works a bit more.

    Now to pass the parameter you want to look up param it's how powershell tells you to pass arguments and should be what you need
     
  3. Atomic

    Atomic Gerwaff

    Joined:
    6 May 2002
    Posts:
    9,646
    Likes Received:
    94

Share This Page