Advertisement
Guest User

Reset Tool

a guest
Dec 18th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. #Generates a random password 9 characters in length
  2. $ErrorActionPrefence = "SilentlyContinue"
  3. $ascii=$NULL;For ($a=48;$a –le 122;$a++) {$ascii+=,[char][byte]$a }
  4. Function GET-Temppassword() {
  5. Param(
  6. [int]$length=9,
  7. [string[]]$sourcedata
  8. )
  9.  
  10. For ($loop=1; $loop –le $length; $loop++) {
  11. $TempPassword+=($sourcedata | GET-RANDOM)
  12. }
  13. return $TempPassword
  14. }
  15.  
  16. #Sets the variable to generate the random password
  17. $temPassword = GET-Temppassword –length 9 –sourcedata $ascii
  18.  
  19. #ERASE ALL THIS AND PUT XAML BELOW between the @" "@
  20. $inputXML = @"
  21. <Window x:Class="WpfApplication2.MainWindow"
  22. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  23. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  24. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  25. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  26. xmlns:local="clr-namespace:WpfApplication2"
  27. mc:Ignorable="d"
  28. Title="Reset Password" Height="350" Width="525">
  29. <Grid>
  30. <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"/>
  31. <Button x:Name="button" Content="Reset" HorizontalAlignment="Left" Margin="219,270,0,0" VerticalAlignment="Top" Width="75"/>
  32. <Label x:Name="label" Content="Email Address" HorizontalAlignment="Left" Height="29" Margin="84,153,0,0" VerticalAlignment="Top" Width="92"/>
  33. <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="29" Margin="211,153,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="117"/>
  34. <Label x:Name="label1" Content="Password" HorizontalAlignment="Left" Height="28" Margin="84,206,0,0" VerticalAlignment="Top" Width="92"/>
  35. <TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="28" Margin="211,206,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="117"/>
  36. <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"/>
  37.  
  38. </Grid>
  39. </Window>
  40. "@
  41.  
  42. $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
  43.  
  44.  
  45. [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  46. [xml]$XAML = $inputXML
  47. #Read XAML
  48.  
  49. $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  50. try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  51. catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
  52.  
  53. #===========================================================================
  54. # Load XAML Objects In PowerShell
  55. #===========================================================================
  56.  
  57. $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
  58.  
  59. Function Get-FormVariables{
  60. if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
  61. write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
  62. get-variable WPF*
  63. }
  64.  
  65. Get-FormVariables
  66.  
  67. #===========================================================================
  68. # Actually make the objects work
  69. #===========================================================================
  70.  
  71. #Connects to MS Online
  72. connect-msolservice
  73.  
  74. $WPFtextBox1.Text = $temPassword
  75. $WPFbutton.Add_Click({Set-MsolUserPassword -UserPrincipal $WPFtextBox.Text -NewPassword $temPassword})
  76. $WPFbutton.Add_Click({
  77. if($WPFimage1.Visibility -ne 'Visible') {$WPFimage1.Visibility = 'Visible'}
  78. else{$WPFimage1.Visibility = 'Hidden'}
  79. })
  80.  
  81. #Sample entry of how to add data to a field
  82.  
  83. #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
  84.  
  85. #===========================================================================
  86. # Shows the form
  87. #===========================================================================
  88. $form.ShowDialog() | Out-Null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement