Created
May 10, 2016 17:17
-
-
Save anonymous/2ea3eaa7ab505a17b8507612d9e2bde4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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="Account Search" Height="350" Width="525"> | |
<Grid> | |
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="186,35,0,0" TextWrapping="Wrap" Text="Get AD Account Information" VerticalAlignment="Top" Height="62" Width="185"/> | |
<Button x:Name="button" Content="OK" HorizontalAlignment="Left" Margin="401,265,0,0" VerticalAlignment="Top" Width="75"/> | |
<Label x:Name="label" Content="UserName" HorizontalAlignment="Left" Margin="44,188,0,0" VerticalAlignment="Top"/> | |
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="186,191,0,0" TextWrapping="Wrap" Text="Enter UserName" VerticalAlignment="Top" Width="120"/> | |
</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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment