SHOW:
|
|
- or go back to the newest paste.
| 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" |
| 9 | + | <Window x:Class="FileVersionChecker.MainWindow" |
| 10 | - | xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
| 10 | + | xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
| 11 | - | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
| 11 | + | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
| 12 | - | xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
| 12 | + | xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
| 13 | - | xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
| 13 | + | xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
| 14 | - | xmlns:local="clr-namespace:WpfApplication1" |
| 14 | + | xmlns:local="clr-namespace:FileVersionChecker" |
| 15 | - | mc:Ignorable="d" |
| 15 | + | mc:Ignorable="d" |
| 16 | - | Title="PowerTool" Height="400" Width="575"> |
| 16 | + | Title="FileVersionChecker" Height="350" Width="525"> |
| 17 | <Grid Background="#FF0B4A80" > | |
| 18 | - | <TabControl x:Name="tabControl" SelectionChanged="tabControl_SelectionChanged"> |
| 18 | + | <TabControl x:Name="tabControl"> |
| 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."}
|
| 63 | + | catch{Write-Warning "Unable to parse XML, with error: $($Error[0])`n Ensure that there are NO SelectionChanged properties (PowerShell cannot process them)"
|
| 64 | throw} | |
| 65 | ||
| 66 | #=========================================================================== | |
| 67 | # Load XAML Objects In PowerShell | |
| 68 | #=========================================================================== | |
| 69 | - | $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
|
| 69 | + | |
| 70 | $xaml.SelectNodes("//*[@Name]") | %{"trying item $($_.Name)";
| |
| 71 | try {Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name) -ErrorAction Stop}
| |
| 72 | catch{throw}
| |
| 73 | } | |
| 74 | ||
| 75 | Function Get-FormVariables{
| |
| 76 | if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
| |
| 77 | write-host "Found the following interactable elements from our form" -ForegroundColor Cyan | |
| 78 | get-variable WPF* | |
| 79 | } | |
| 80 | ||
| 81 | Get-FormVariables | |
| 82 | ||
| 83 | #=========================================================================== | |
| 84 | # Actually make the objects work | |
| 85 | #=========================================================================== | |
| 86 | ||
| 87 | #Sample entry of how to add data to a field | |
| 88 | ||
| 89 | #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
| |
| 90 | ||
| 91 | #=========================================================================== | |
| 92 | # Shows the form | |
| 93 | #=========================================================================== | |
| 94 | write-host "To show the form, run the following" -ForegroundColor Cyan | |
| 95 | $Form.ShowDialog() | out-null |