Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cls
- try{
- Add-Type -AssemblyName PresentationCore,PresentationFramework,WindowsBase,system.windows.forms
- write-Host "OK"
- } catch {
- Throw "Failed to load Windows Presentation Framework assemblies."
- }
- $inputXML = @"
- <Window 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="PowerTool" Height="400" Width="575">
- <Grid Background="#FF0B4A80" >
- <TabControl x:Name="tabControl" SelectionChanged="tabControl_SelectionChanged">
- <TabItem Header="Inventory">
- <Grid Background="#FF0B4A80" Margin="0,-3,0,3">
- <Image x:Name="systran_png" Margin="475,10,10,252" Source="systran.png" Stretch="Fill"/>
- <RadioButton x:Name="Computer" Content="Computer" HorizontalAlignment="Left" Margin="10,16,0,0" VerticalAlignment="Top" />
- <RadioButton x:Name="Printer" Content="Printer" HorizontalAlignment="Left" Margin="10,45,0,0" VerticalAlignment="Top"/>
- <TextBox x:Name="ObjectName" HorizontalAlignment="Left" Height="26" Margin="10,87,0,0" TextWrapping="Wrap" Text="Name" VerticalAlignment="Top" Width="93"/>
- <Button x:Name="launch" Content="Go !" HorizontalAlignment="Left" Height="52" Margin="488,276,0,0" VerticalAlignment="Top" Width="59"/>
- <CheckBox x:Name="cb_Name" Content="CheckBox" HorizontalAlignment="Left" Height="13" Margin="17,130,0,0" VerticalAlignment="Top" Width="13"/>
- <CheckBox x:Name="cb_OS" Content="CheckBox" HorizontalAlignment="Left" Height="13" Margin="17,155,0,0" VerticalAlignment="Top" Width="13"/>
- <CheckBox x:Name="cb_IP" Content="CheckBox" HorizontalAlignment="Left" Height="13" Margin="17,180,0,0" VerticalAlignment="Top" Width="13"/>
- <CheckBox x:Name="cb_CN" Content="CheckBox" HorizontalAlignment="Left" Height="13" Margin="17,205,0,0" VerticalAlignment="Top" Width="13"/>
- <CheckBox x:Name="cb_Location" Content="CheckBox" HorizontalAlignment="Left" Height="13" Margin="17,230,0,0" VerticalAlignment="Top" Width="13"/>
- <TextBlock x:Name="txt_Name" HorizontalAlignment="Left" Margin="35,130,0,0" TextWrapping="Wrap" Text="Name" VerticalAlignment="Top"/>
- <TextBlock x:Name="txt_OS" HorizontalAlignment="Left" Margin="35,155,0,0" TextWrapping="Wrap" Text="OS" VerticalAlignment="Top"/>
- <TextBlock x:Name="txt_IP" HorizontalAlignment="Left" Margin="35,180,0,0" TextWrapping="Wrap" Text="IPV4" VerticalAlignment="Top"/>
- <TextBlock x:Name="txt_CN" HorizontalAlignment="Left" Margin="35,205,0,0" TextWrapping="Wrap" Text="CanonicalName" VerticalAlignment="Top"/>
- <TextBlock x:Name="txt_Location" HorizontalAlignment="Left" Margin="35,230,0,0" TextWrapping="Wrap" Text="Location" VerticalAlignment="Top"/>
- <TextBlock x:Name="txt_filter" HorizontalAlignment="Left" Height="20" Margin="108,90,0,0" TextWrapping="Wrap" Text="Filter" VerticalAlignment="Top" Width="60"/>
- </Grid>
- </TabItem>
- <TabItem Header="AD add">
- <Grid Background="#FFE5E5E5"/>
- </TabItem>
- <TabItem Header="O365">
- <Grid Background="#FFE5E5E5"/>
- </TabItem>
- <TabItem Header="Status">
- <Grid Background="#FFE5E5E5"/>
- </TabItem>
- <TabItem Header="TODO">
- <Grid Background="#FFE5E5E5"/>
- </TabItem>
- </TabControl>
- <Button x:Name="button1" Content="Quit" Height="20" Width="150" Margin="417,1,0,349"/>
- </Grid>
- </Window>
- "@
- $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
- [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
- [xml]$xaml = $inputXML
- #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. Double-check syntax and ensure .net is installed."}
- #===========================================================================
- # Load XAML Objects In PowerShell
- #===========================================================================
- $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
- Function Get-FormVariables{
- if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
- write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
- get-variable WPF*
- }
- Get-FormVariables
- #===========================================================================
- # Actually make the objects work
- #===========================================================================
- #Sample entry of how to add data to a field
- #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
- #===========================================================================
- # Shows the form
- #===========================================================================
- write-host "To show the form, run the following" -ForegroundColor Cyan
- $Form.ShowDialog() | out-null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement