Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Generates a random password 9 characters in length
- $ErrorActionPrefence = "SilentlyContinue"
- $ascii=$NULL;For ($a=48;$a –le 122;$a++) {$ascii+=,[char][byte]$a }
- Function GET-Temppassword() {
- Param(
- [int]$length=9,
- [string[]]$sourcedata
- )
- For ($loop=1; $loop –le $length; $loop++) {
- $TempPassword+=($sourcedata | GET-RANDOM)
- }
- return $TempPassword
- }
- #Sets the variable to generate the random password
- $temPassword = GET-Temppassword –length 9 –sourcedata $ascii
- #ERASE ALL THIS AND PUT XAML BELOW between the @" "@
- $inputXML = @"
- <Window x:Class="WpfApplication2.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:WpfApplication2"
- mc:Ignorable="d"
- Title="Reset Password" Height="350" Width="525">
- <Grid>
- <Image x:Name="image" HorizontalAlignment="Left" Height="27" Margin="31,35,0,0" VerticalAlignment="Top" Width="121" Source="C:\Users\chendley\Downloads\seismic_logo.png"/>
- <Button x:Name="button" Content="Reset" HorizontalAlignment="Left" Margin="219,270,0,0" VerticalAlignment="Top" Width="75"/>
- <Label x:Name="label" Content="Email Address" HorizontalAlignment="Left" Height="29" Margin="84,153,0,0" VerticalAlignment="Top" Width="92"/>
- <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="29" Margin="211,153,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="117"/>
- <Label x:Name="label1" Content="Password" HorizontalAlignment="Left" Height="28" Margin="84,206,0,0" VerticalAlignment="Top" Width="92"/>
- <TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="28" Margin="211,206,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="117"/>
- <Image x:Name="image1" HorizontalAlignment="Left" Height="88" Margin="219,35,0,0" VerticalAlignment="Top" Width="89" Source="C:\PowerShell\Images\fallout.jpg" Visibility="Hidden"/>
- </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
- #===========================================================================
- #Connects to MS Online
- connect-msolservice
- $WPFtextBox1.Text = $temPassword
- $WPFbutton.Add_Click({Set-MsolUserPassword -UserPrincipal $WPFtextBox.Text -NewPassword $temPassword})
- $WPFbutton.Add_Click({
- if($WPFimage1.Visibility -ne 'Visible') {$WPFimage1.Visibility = 'Visible'}
- else{$WPFimage1.Visibility = 'Hidden'}
- })
- #Sample entry of how to add data to a field
- #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
- #===========================================================================
- # Shows the form
- #===========================================================================
- $form.ShowDialog() | Out-Null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement