Advertisement
Guest User

GUI

a guest
Oct 12th, 2017
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cls
  2. try{
  3.  Add-Type -AssemblyName PresentationCore,PresentationFramework,WindowsBase,system.windows.forms
  4.  write-Host "OK"
  5. } catch {
  6.  Throw "Failed to load Windows Presentation Framework assemblies."
  7. }
  8. $inputXML = @"
  9. <Window x:Class="WpfApplication1.MainWindow"
  10.    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  11.    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  12.    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  13.    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  14.    xmlns:local="clr-namespace:WpfApplication1"
  15.    mc:Ignorable="d"
  16.    Title="PowerTool" Height="400" Width="575">
  17.    <Grid Background="#FF0B4A80" >
  18.         <TabControl x:Name="tabControl" SelectionChanged="tabControl_SelectionChanged">
  19.             <TabItem Header="Inventory">
  20.                 <Grid Background="#FF0B4A80" Margin="0,-3,0,3">
  21.                     <Image x:Name="systran_png" Margin="475,10,10,252" Source="systran.png" Stretch="Fill"/>
  22.                     <RadioButton x:Name="Computer" Content="Computer" HorizontalAlignment="Left" Margin="10,16,0,0" VerticalAlignment="Top" />
  23.                     <RadioButton x:Name="Printer" Content="Printer" HorizontalAlignment="Left" Margin="10,45,0,0" VerticalAlignment="Top"/>
  24.                     <TextBox x:Name="ObjectName" HorizontalAlignment="Left" Height="26" Margin="10,87,0,0" TextWrapping="Wrap" Text="Name" VerticalAlignment="Top" Width="93"/>
  25.                     <Button x:Name="launch" Content="Go !" HorizontalAlignment="Left" Height="52" Margin="488,276,0,0" VerticalAlignment="Top" Width="59"/>
  26.                     <CheckBox x:Name="cb_Name" Content="CheckBox" HorizontalAlignment="Left" Height="13" Margin="17,130,0,0" VerticalAlignment="Top" Width="13"/>
  27.                     <CheckBox x:Name="cb_OS" Content="CheckBox" HorizontalAlignment="Left" Height="13" Margin="17,155,0,0" VerticalAlignment="Top" Width="13"/>
  28.                     <CheckBox x:Name="cb_IP" Content="CheckBox" HorizontalAlignment="Left" Height="13" Margin="17,180,0,0" VerticalAlignment="Top" Width="13"/>
  29.                     <CheckBox x:Name="cb_CN" Content="CheckBox" HorizontalAlignment="Left" Height="13" Margin="17,205,0,0" VerticalAlignment="Top" Width="13"/>
  30.                     <CheckBox x:Name="cb_Location" Content="CheckBox" HorizontalAlignment="Left" Height="13" Margin="17,230,0,0" VerticalAlignment="Top" Width="13"/>
  31.                     <TextBlock x:Name="txt_Name" HorizontalAlignment="Left" Margin="35,130,0,0" TextWrapping="Wrap" Text="Name" VerticalAlignment="Top"/>
  32.                     <TextBlock x:Name="txt_OS" HorizontalAlignment="Left" Margin="35,155,0,0" TextWrapping="Wrap" Text="OS" VerticalAlignment="Top"/>
  33.                     <TextBlock x:Name="txt_IP" HorizontalAlignment="Left" Margin="35,180,0,0" TextWrapping="Wrap" Text="IPV4" VerticalAlignment="Top"/>
  34.                     <TextBlock x:Name="txt_CN" HorizontalAlignment="Left" Margin="35,205,0,0" TextWrapping="Wrap" Text="CanonicalName" VerticalAlignment="Top"/>
  35.                     <TextBlock x:Name="txt_Location" HorizontalAlignment="Left" Margin="35,230,0,0" TextWrapping="Wrap" Text="Location" VerticalAlignment="Top"/>
  36.                     <TextBlock x:Name="txt_filter" HorizontalAlignment="Left" Height="20" Margin="108,90,0,0" TextWrapping="Wrap" Text="Filter" VerticalAlignment="Top" Width="60"/>
  37.                 </Grid>
  38.             </TabItem>
  39.             <TabItem Header="AD add">
  40.                 <Grid Background="#FFE5E5E5"/>
  41.             </TabItem>
  42.             <TabItem Header="O365">
  43.                 <Grid Background="#FFE5E5E5"/>
  44.             </TabItem>
  45.             <TabItem Header="Status">
  46.                 <Grid Background="#FFE5E5E5"/>
  47.             </TabItem>
  48.             <TabItem Header="TODO">
  49.                 <Grid Background="#FFE5E5E5"/>
  50.             </TabItem>
  51.         </TabControl>
  52.         <Button x:Name="button1" Content="Quit" Height="20" Width="150" Margin="417,1,0,349"/>
  53.     </Grid>
  54. </Window>
  55. "@
  56.  
  57. $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'
  58. [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  59. [xml]$xaml = $inputXML
  60. #Read XAML
  61. $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  62. try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  63. catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
  64.  
  65. #===========================================================================
  66. # Load XAML Objects In PowerShell
  67. #===========================================================================
  68.  
  69. $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
  70.  
  71. Function Get-FormVariables{
  72. if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
  73. write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
  74. get-variable WPF*
  75. }
  76.  
  77. Get-FormVariables
  78.  
  79. #===========================================================================
  80. # Actually make the objects work
  81. #===========================================================================
  82.  
  83. #Sample entry of how to add data to a field
  84.  
  85. #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
  86.  
  87. #===========================================================================
  88. # Shows the form
  89. #===========================================================================
  90. write-host "To show the form, run the following" -ForegroundColor Cyan
  91. $Form.ShowDialog() | out-null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement