Guest User

Error

a guest
Jun 14th, 2018
158
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. <Window x:Class="WpfApp1.MainWindow"
  4.        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  5.        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  6.        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7.        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8.        xmlns:local="clr-namespace:WpfApp1;assembly=WpfApp1Assembly"
  9.        mc:Ignorable="d"
  10.        Title="HG Folder &amp; Permission Deployment" Height="350" Width="525">
  11.    <Grid RenderTransformOrigin="0.511,0.507" Background="{x:Null}">
  12.        <Image HorizontalAlignment="Left" Height="100" Margin="10,10,0,0" Name="Image" VerticalAlignment="Top" Width="70" Source="C:\Users\jfitzgerald\Pictures\img1.jpg"/>
  13.        <TextBlock HorizontalAlignment="Left" Margin="115,10,0,0" Name="TextBlock" TextWrapping="Wrap" Text="This useful tool is a front end for a powerful PowerShell script that will allow you to deploy a propertie's folder and subfolders, with the proper permissions, in the Review drive." VerticalAlignment="Top" Height="97" Width="392"/>
  14.        <Button Content="OK" HorizontalAlignment="Left" Name="Button" Margin="432,289,0,0" VerticalAlignment="Top" Width="75"/>
  15.        <Label Content="Username&#xD;&#xA;" Name="Label" HorizontalAlignment="Left" Margin="81,172,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Width="63" Height="26"/>
  16.        <TextBox HorizontalAlignment="Left" Name="TextBox" Height="23" Margin="158,175,0,0" TextWrapping="Wrap" Text="Enter Your Username" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0.499,0.456"/>
  17.  
  18.    </Grid>
  19. </Window>
  20. "@      
  21.  
  22. $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
  23.  
  24. [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  25. [xml]$XAML = $inputXML
  26.  
  27. #Read XAML
  28.  
  29.    $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  30. try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  31. catch{Write-Warning "Unable to parse XML, with error: $($Error[0])`n Ensure that there are NO SelectionChanged properties (PowerShell cannot process them)"
  32.    throw}
  33.  
  34. #===========================================================================
  35. # Load XAML Objects In PowerShell
  36. #===========================================================================
  37.  
  38. $xaml.SelectNodes("//*[@Name]") | %{"trying item $($_.Name)";
  39.    try {Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name) -ErrorAction Stop}
  40.    catch{throw}
  41.    }
  42.  
  43. Function Get-FormVariables{
  44. if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
  45. write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
  46. get-variable WPF*
  47. }
  48.  
  49. Get-FormVariables
  50.  
  51. #===========================================================================
  52. # Actually make the objects work
  53. #===========================================================================
  54.  
  55. #Sample entry of how to add data to a field
  56.  
  57. #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
  58.  
  59. #===========================================================================
  60. # Shows the form
  61. #===========================================================================
  62. write-host "To show the form, run the following" -ForegroundColor Cyan
  63. '$Form.ShowDialog() | out-null'
  64. WARNING: Unable to parse XML, with error: Exception calling "Load" with "1" argument(s): "Cannot create unknown type '{http://schemas.microsoft.com/winfx/2006/xaml/presentation}Null'."
  65. Ensure that there are NO SelectionChanged properties (PowerShell cannot process them)
  66. Exception calling "Load" with "1" argument(s): "Cannot create unknown type '{http://schemas.microsoft.com/winfx/2006/xaml/presentation}Null'."
  67. At line:30 char:5
  68. + try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  69. +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  70.    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
  71.    + FullyQualifiedErrorId : XamlParseException
RAW Paste Data