Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ERASE ALL THIS AND PUT XAML BELOW between the @" "@
- $inputXML = @"
- <Window x:Class="WpfApp1.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:WpfApp1"
- mc:Ignorable="d"
- Title="Onboarding Tool" Height="762.272" Width="525">
- <Grid>
- <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"/>
- <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"/>
- <TextBox x:Name="LogonTextbox" HorizontalAlignment="Left" Height="23" Margin="338,156,0,0" TextWrapping="Wrap" Text="Enter Logon Name" VerticalAlignment="Top" Width="120"/>
- <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"/>
- <TextBox x:Name="FirstNameTextBox" HorizontalAlignment="Left" Height="23" Margin="109,158,0,0" TextWrapping="Wrap" Text="Enter First Name" VerticalAlignment="Top" Width="109"/>
- <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"/>
- <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"/>
- <Label x:Name="ADLabel" Content="Active Directory" HorizontalAlignment="Left" Height="30" Margin="42,123,0,0" VerticalAlignment="Top" Width="112" FontWeight="Bold"/>
- <TextBox x:Name="LastNameTextBox" HorizontalAlignment="Left" Height="23" Margin="109,186,0,0" TextWrapping="Wrap" Text="Enter Last Name" VerticalAlignment="Top" Width="109"/>
- <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"/>
- <Label x:Name="PasswordLabel" Content="Password" HorizontalAlignment="Left" Height="23" Margin="10,214,0,0" VerticalAlignment="Top" Width="94" RenderTransformOrigin="-0.036,0.554"/>
- <CheckBox x:Name="PasswordOnLoginCheckBox" Content="Change Password On Login" HorizontalAlignment="Left" Margin="10,242,0,0" VerticalAlignment="Top" Width="208"/>
- <Button x:Name="CreateUserButton" Content="Create User" HorizontalAlignment="Left" Height="27" Margin="338,225,0,0" VerticalAlignment="Top" Width="120"/>
- <TextBox X:Name="Group1Text" HorizontalAlignment="Left" Height="23" Margin="338,186,0,0" TextWrapping="Wrap" Text="Group" VerticalAlignment="Top" Width="120"/>
- <Label x:Name="GroupLabel" Content="Group" HorizontalAlignment="Left" Height="24" Margin="239,186,0,0" VerticalAlignment="Top" Width="82"/>
- </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."}
- #===========================================================================
- # Store Form 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
- #===========================================================================
- $defaultOU = (Get-ADObject -filter 'OBjectClass -eq "domain"' -Properties wellKnownObjects).wellknownobjects.split("'n")[-1].split(':') | select -Last 1
- function Get-FormFields {
- $HashArguments =
- @{ Name = $WPFLogonTextBox.Text;
- GivenName = $WPFFirstNameTextBox.Text;
- Surname=$WPFLastNameTextBox.Text;
- AccountPassword = ($WPFPasswordTextBox.Text | ConvertTo-SecureString -AsPlainText -Force);
- Path=$defaultOU
- }
- }
- $defaultOU,"OU=INS_USERS,DC=WIN-95T9NBKFU8L,DC=local"
- $WPFCreateUserButton.add_Click({
- $hash = Get-FormFields
- New-ADUser @hash -PassThru
- $form.close()})
- #===========================================================================
- # Shows the form
- #===========================================================================
- write-host "To show the form, run the following" -ForegroundColor Cyan
- '$Form.ShowDialog() | out-null'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement