Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
178
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. <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"
  9.        mc:Ignorable="d"
  10.        Title="Onboarding Tool" Height="762.272" Width="525">
  11.    <Grid>
  12.        <Image x:Name="StaffBoomLogo" HorizontalAlignment="Left" Height="96" Margin="211,10,0,0" VerticalAlignment="Top" Width="96" Source="C:\Users\lbair\My SecuriSync\IT Department\_Staff Boom\Branding\StaffBoomLogo_96x96.jpg"/>
  13.        <TextBlock x:Name="Title" HorizontalAlignment="Left" Height="17" Margin="159,106,0,0" TextWrapping="Wrap" Text="StaffBoom Onboarding Tool" VerticalAlignment="Top" Width="202" TextAlignment="Center" FontFamily="Comic Sans MS" RenderTransformOrigin="-0.74,2.361"/>
  14.        <TextBox x:Name="LogonTextbox" HorizontalAlignment="Left" Height="23" Margin="338,156,0,0" TextWrapping="Wrap" Text="Enter Logon Name" VerticalAlignment="Top" Width="120"/>
  15.        <Label x:Name="LogonLabel" Content="Logon Name" HorizontalAlignment="Left" Height="23" Margin="239,156,0,0" VerticalAlignment="Top" Width="94" RenderTransformOrigin="-0.036,0.554"/>
  16.        <TextBox x:Name="FirstNameTextBox" HorizontalAlignment="Left" Height="23" Margin="109,158,0,0" TextWrapping="Wrap" Text="Enter First Name" VerticalAlignment="Top" Width="109"/>
  17.        <Label x:Name="FirstNameLabel" Content="First Name" HorizontalAlignment="Left" Height="23" Margin="10,158,0,0" VerticalAlignment="Top" Width="94" RenderTransformOrigin="-0.036,0.554"/>
  18.        <Label x:Name="LastNameLabel" Content="Last Name" HorizontalAlignment="Left" Height="23" Margin="10,186,0,0" VerticalAlignment="Top" Width="94" RenderTransformOrigin="-0.036,0.554"/>
  19.        <Label x:Name="ADLabel" Content="Active Directory" HorizontalAlignment="Left" Height="30" Margin="42,123,0,0" VerticalAlignment="Top" Width="112" FontWeight="Bold"/>
  20.        <TextBox x:Name="LastNameTextBox" HorizontalAlignment="Left" Height="23" Margin="109,186,0,0" TextWrapping="Wrap" Text="Enter Last Name" VerticalAlignment="Top" Width="109"/>
  21.        <TextBox x:Name="PasswordTextBox" HorizontalAlignment="Left" Height="23" Margin="109,214,0,0" TextWrapping="Wrap" Text="Password" VerticalAlignment="Top" Width="109" RenderTransformOrigin="0.479,4.522"/>
  22.        <Label x:Name="PasswordLabel" Content="Password" HorizontalAlignment="Left" Height="23" Margin="10,214,0,0" VerticalAlignment="Top" Width="94" RenderTransformOrigin="-0.036,0.554"/>
  23.        <CheckBox x:Name="PasswordOnLoginCheckBox" Content="Change Password On Login" HorizontalAlignment="Left" Margin="10,242,0,0" VerticalAlignment="Top" Width="208"/>
  24.        <Button x:Name="CreateUserButton" Content="Create User" HorizontalAlignment="Left" Height="27" Margin="338,225,0,0" VerticalAlignment="Top" Width="120"/>
  25.        <TextBox X:Name="Group1Text" HorizontalAlignment="Left" Height="23" Margin="338,186,0,0" TextWrapping="Wrap" Text="Group" VerticalAlignment="Top" Width="120"/>
  26.        <Label x:Name="GroupLabel" Content="Group" HorizontalAlignment="Left" Height="24" Margin="239,186,0,0" VerticalAlignment="Top" Width="82"/>
  27.  
  28.    </Grid>
  29. </Window>
  30.  
  31. "@      
  32.  
  33. $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'
  34.  
  35. [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  36. [xml]$XAML = $inputXML
  37. #Read XAML
  38.  
  39.     $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  40.   try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  41. catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
  42.  
  43. #===========================================================================
  44. # Store Form Objects In PowerShell
  45. #===========================================================================
  46.  
  47. $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
  48.  
  49. Function Get-FormVariables{
  50. if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
  51. write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
  52. get-variable WPF*
  53. }
  54.  
  55. Get-FormVariables
  56.  
  57. #===========================================================================
  58. # Actually make the objects work
  59. #===========================================================================
  60. $defaultOU = (Get-ADObject -filter 'OBjectClass -eq "domain"' -Properties wellKnownObjects).wellknownobjects.split("'n")[-1].split(':') | select -Last 1
  61.  
  62. function Get-FormFields {
  63.  
  64.  
  65.   $HashArguments =
  66.     @{ Name = $WPFLogonTextBox.Text;
  67.        GivenName = $WPFFirstNameTextBox.Text;
  68.        Surname=$WPFLastNameTextBox.Text;
  69.        AccountPassword = ($WPFPasswordTextBox.Text | ConvertTo-SecureString -AsPlainText -Force);
  70.        Path=$defaultOU
  71.        }
  72.        }
  73.  
  74.        $defaultOU,"OU=INS_USERS,DC=WIN-95T9NBKFU8L,DC=local"
  75.        
  76.  
  77.        $WPFCreateUserButton.add_Click({
  78.        $hash = Get-FormFields
  79.        New-ADUser @hash -PassThru
  80.        $form.close()})
  81.  
  82.  
  83.  
  84. #===========================================================================
  85. # Shows the form
  86. #===========================================================================
  87. write-host "To show the form, run the following" -ForegroundColor Cyan
  88. '$Form.ShowDialog() | out-null'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement