Advertisement
Guest User

PShellVS

a guest
Mar 16th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ERASE ALL THIS AND PUT XAML BELOW between the @" "@
  2. $inputXML = @"
  3.  
  4. <Window x:Class="stgmenu.MainWindow"
  5.        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  6.        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  7.        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  8.        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  9.        xmlns:local="clr-namespace:stgmenu"
  10.        mc:Ignorable="d"
  11.        Title="MainWindow" Height="665.799" Width="799.492">
  12.    <Grid>
  13.        <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="14,9,0,0" TextWrapping="Wrap" VerticalAlignment="Top"><Run Text="Server"/><LineBreak/><Run/></TextBlock>
  14.        <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="13,31,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
  15.        <ListView x:Name="listView" HorizontalAlignment="Left" Height="600" Margin="372,14,0,0" VerticalAlignment="Top" Width="410">
  16.            <ListView.View>
  17.                <GridView>
  18.                    <GridViewColumn/>
  19.                </GridView>
  20.            </ListView.View>
  21.        </ListView>
  22.        <Button x:Name="button" Content="keepalive" HorizontalAlignment="Left" Margin="20,82,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="0.42,0.162"/>
  23.  
  24.    </Grid>
  25. </Window>
  26.  
  27.  
  28. "@      
  29.  
  30. $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'
  31.  
  32.  
  33. [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  34. [xml]$XAML = $inputXML
  35. #Read XAML
  36.  
  37.     $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  38.   try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  39. catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
  40.  
  41. #===========================================================================
  42. # Load XAML Objects In PowerShell
  43. #===========================================================================
  44.  
  45. $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
  46.  
  47. Function Get-FormVariables{
  48. if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
  49. write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
  50. get-variable WPF*
  51. }
  52.  
  53. Get-FormVariables
  54.  
  55. #===========================================================================
  56. # Actually make the objects work
  57. #===========================================================================
  58.  
  59.  
  60. #Sample entry of how to add data to a field
  61.  
  62. #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
  63.  
  64. #===========================================================================
  65. # Shows the form
  66. #===========================================================================
  67. write-host "To show the form, run the following" -ForegroundColor Cyan
  68. '$Form.ShowDialog() | out-null'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement