Advertisement
1RedOne

Updated Code

Oct 24th, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $inputXML= @"
  2. <Window x:Class="Powershell_Control_Panel.MainWindow"
  3.        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4.        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5.        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6.        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  7.        xmlns:local="clr-namespace:Powershell_Control_Panel"
  8.        mc:Ignorable="d"
  9.        Title="Wiggle Accounts Control Panel" Height="614.706" Width="821.803">
  10.    <Grid Margin="0,0,2,-4">
  11.        <Grid.RowDefinitions>
  12.            <RowDefinition Height="121*"/>
  13.            <RowDefinition Height="467*"/>
  14.        </Grid.RowDefinitions>
  15.        <Grid.ColumnDefinitions>
  16.            <ColumnDefinition Width="65*"/>
  17.            <ColumnDefinition Width="65*"/>
  18.            <ColumnDefinition Width="73*"/>
  19.        </Grid.ColumnDefinitions>
  20.        <Button x:Name="button" Content="Disable Account" HorizontalAlignment="Left" Height="45" Margin="60,30,0,0" VerticalAlignment="Top" Width="140" Grid.Row="1">
  21.            <Button.Effect>
  22.                <DropShadowEffect/>
  23.            </Button.Effect>
  24.        </Button>
  25.        <Button x:Name="button_Copy" Content="Enable Account" HorizontalAlignment="Left" Height="45" Margin="60,98,0,0" VerticalAlignment="Top" Width="140" Grid.Row="1">
  26.            <Button.Effect>
  27.                <DropShadowEffect/>
  28.            </Button.Effect>
  29.        </Button>
  30.        <Button x:Name="button_Copy1" Content="Set Account Expiry " HorizontalAlignment="Left" Height="45" Margin="60,239,0,0" VerticalAlignment="Top" Width="140" Grid.Row="1">
  31.            <Button.Effect>
  32.                <DropShadowEffect/>
  33.            </Button.Effect>
  34.        </Button>
  35.        <Button x:Name="button_Copy2" Content="" HorizontalAlignment="Left" Height="45" VerticalAlignment="Top" Width="140" Grid.Column="2" Grid.Row="1" Margin="70,30,0,0">
  36.            <Button.Effect>
  37.                <DropShadowEffect/>
  38.            </Button.Effect>
  39.        </Button>
  40.        <Button x:Name="button_Copy3" Content="" HorizontalAlignment="Left" Height="45" Margin="70,98,0,0" VerticalAlignment="Top" Width="140" Grid.Column="2" Grid.Row="1">
  41.            <Button.Effect>
  42.                <DropShadowEffect/>
  43.            </Button.Effect>
  44.        </Button>
  45.        <Button x:Name="button_Copy4" Content="" HorizontalAlignment="Left" Height="45" Margin="70,168,0,0" VerticalAlignment="Top" Width="140" Grid.Column="2" Grid.Row="1">
  46.            <Button.Effect>
  47.                <DropShadowEffect/>
  48.            </Button.Effect>
  49.        </Button>
  50.        <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="45" Margin="60,76,0,0" Text="Account Tasks" VerticalAlignment="Top" Width="135"  HorizontalScrollBarVisibility="Auto" Padding="0" TextAlignment="Center" TextWrapping="Wrap" RenderTransformOrigin="0.5,0.5" BorderThickness="0"/>
  51.        <Button x:Name="button_Copy5" Content="Account Name Change" HorizontalAlignment="Left" Height="45" Margin="60,309,0,0" VerticalAlignment="Top" Width="140" Grid.Row="1" >
  52.            <Button.Effect>
  53.                <DropShadowEffect/>
  54.            </Button.Effect>
  55.        </Button>
  56.        <Button x:Name="button_Copy6" Content="Account Information" HorizontalAlignment="Left" Height="45" Margin="60,377,0,0" VerticalAlignment="Top" Width="140" Grid.Row="1" >
  57.            <Button.Effect>
  58.                <DropShadowEffect/>
  59.            </Button.Effect>
  60.        </Button>
  61.        <Button x:Name="button_Copy7" Content="Unblock Account" HorizontalAlignment="Left" Height="45" Margin="60,168,0,0" VerticalAlignment="Top" Width="140" Grid.Row="1">
  62.            <Button.Effect>
  63.                <DropShadowEffect/>
  64.            </Button.Effect>
  65.        </Button>
  66.        <TextBox x:Name="textBox_Copy" HorizontalAlignment="Left" Height="45" Margin="70,76,0,0" Text="Get Information" VerticalAlignment="Top" Width="135" HorizontalScrollBarVisibility="Auto" Padding="0" TextAlignment="Center" TextWrapping="Wrap" RenderTransformOrigin="0.5,0.5" Grid.Column="1" BorderThickness="0"/>
  67.        <Button x:Name="button_Copy8" Content="Get Computer Information" HorizontalAlignment="Left" Height="45" Margin="70,30,0,0" VerticalAlignment="Top" Width="140" Grid.Row="1" Grid.Column="1">
  68.            <Button.Effect>
  69.                <DropShadowEffect/>
  70.            </Button.Effect>
  71.        </Button>
  72.        <Button x:Name="button_Copy9" Content="Get Members of a Group" HorizontalAlignment="Left" Height="45" Margin="70,98,0,0" VerticalAlignment="Top" Width="140" Grid.Row="1" Grid.Column="1">
  73.            <Button.Effect>
  74.                <DropShadowEffect/>
  75.            </Button.Effect>
  76.        </Button>
  77.        <Button x:Name="button_Copy10" Content="Get Mailbox GUID" HorizontalAlignment="Left" Height="45" Margin="70,168,0,0" VerticalAlignment="Top" Width="140" Grid.Row="1" Grid.Column="1">
  78.            <Button.Effect>
  79.                <DropShadowEffect/>
  80.            </Button.Effect>
  81.        </Button>
  82.        <TextBox x:Name="textBox_Copy1" HorizontalAlignment="Left" Height="45" Margin="70,76,0,0" Text="Misc" VerticalAlignment="Top" Width="135" HorizontalScrollBarVisibility="Auto" Padding="0" TextAlignment="Center" TextWrapping="Wrap" RenderTransformOrigin="0.5,0.5" Grid.Column="2" BorderThickness="0"/>
  83.        <Button x:Name="button_Copy11" Content="Check Microsoft Licenses" HorizontalAlignment="Left" Height="45" Margin="70,239,0,0" VerticalAlignment="Top" Width="140" Grid.Row="1" Grid.Column="1">
  84.            <Button.Effect>
  85.                <DropShadowEffect/>
  86.            </Button.Effect>
  87.        </Button>
  88.        <Button x:Name="button_Copy12" Content="" HorizontalAlignment="Left" Height="45" Margin="70,309,0,0" VerticalAlignment="Top" Width="140" Grid.Row="1" Grid.Column="1">
  89.            <Button.Effect>
  90.                <DropShadowEffect/>
  91.            </Button.Effect>
  92.        </Button>
  93.        <Button x:Name="button_Copy13" Content="" HorizontalAlignment="Left" Height="45" Margin="70,377,0,0" VerticalAlignment="Top" Width="140" Grid.Row="1" Grid.Column="1">
  94.            <Button.Effect>
  95.                <DropShadowEffect/>
  96.            </Button.Effect>
  97.        </Button>
  98.    </Grid>
  99. </Window>
  100.  
  101. "@
  102.  
  103. $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'
  104.  
  105. [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  106. [xml]$XAML = $inputXML
  107. #Read XAML
  108.  
  109.     $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  110.   try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  111. catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
  112.  
  113. #===========================================================================
  114. # Load XAML Objects In PowerShell
  115. #===========================================================================
  116.  
  117. $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
  118.  
  119. Function Get-FormVariables{
  120. if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
  121. write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
  122. get-variable WPF*
  123. }
  124.  
  125. Get-FormVariables
  126.  
  127. #===========================================================================
  128. # Actually make the objects work
  129. #===========================================================================
  130.  
  131. #Sample entry of how to add data to a field
  132.  
  133. #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
  134.  
  135. #===========================================================================
  136. # Shows the form
  137. #===========================================================================
  138. write-host "To show the form, run the following" -ForegroundColor Cyan
  139. $Form.ShowDialog() | out-null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement