Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region FORM LOAD
- $MainForm_Load = {
- $isadmin = isadmin
- IF ($isadmin -eq $false)
- {
- $is = Invoke-PopUp -Title 'Error!' -Message 'Current user must be an Administrator. You may also right click this executable, and select "Run As Administrator." The script will now exit.' -IconType Error -ButtonType OK
- IF ($is -eq 'OK')
- {
- EXIT;
- }
- }
- FOREACH ($U in (Get-LocalUsers)) { $cbLocalAccount.Items.Add($U) }
- }
- #endregion FORM LOAD
- #region GLOBAL VARIABLES
- #endregion
- #region FORM FUNCTIONS
- function isadmin
- {
- # Returns true/false
- ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
- }
- FUNCTION Invoke-PopUp
- {
- [CMDLETBINDING()]
- PARAM (
- [Parameter(Mandatory = $true, Position = 0)]
- [string]$Title,
- [Parameter(Mandatory = $true, Position = 1)]
- [string]$Message,
- [PARAMETER(Mandatory = $true, Position = 2)]
- [ValidateSet(
- 'Asterisk',
- 'Error',
- 'Exclamation',
- 'Hand',
- 'Information',
- 'None',
- 'Question',
- 'Stop',
- 'Warning')]
- [string]$IconType,
- [PARAMETER(Mandatory = $false, Position = 3)]
- [ValidateSet(
- 'AbortRetryIgnore',
- 'OK',
- 'OKCancel',
- 'RetryCancel',
- 'YesNo',
- 'YesNoCancel'
- )]
- [string]$ButtonType
- )
- [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
- $m = [Windows.Forms.MessageBox]::Show($Message, $Title, [Windows.Forms.MessageBoxButtons]::$ButtonType, [Windows.Forms.MessageBoxIcon]::$IconType)
- return $m
- }
- FUNCTION Add-Logs ($Text)
- {
- $Date = Get-Date
- $TextValue = "$Date | $Text`r`n"
- $rtbLogs.Text += $TextValue
- }
- FUNCTION Get-LocalUsers
- {
- $a = NET USER | Select-Object -skip 4
- $a = $a | Select-Object -First ($a.Count - 2)
- $a = $a.Trim()
- $a -split '\s{2,}'
- }
- FUNCTION Set-AutoLogon
- {
- [CmdletBinding()]
- Param (
- [Parameter(Mandatory = $True, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [String[]]$DefaultUsername,
- [Parameter(Mandatory = $True, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [String[]]$DefaultPassword,
- [Parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [AllowEmptyString()]
- [string]$DefaultDomain,
- [Parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [AllowEmptyString()]
- [string]$RunAsUsername,
- [Parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [AllowEmptyString()]
- [string]$RunAsPassword,
- [Parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [AllowEmptyString()]
- [String[]]$AutoLogonCount,
- [Parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [AllowEmptyString()]
- [String[]]$Script
- )
- BEGIN
- {
- #Registry path declaration
- $RegPath = "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]"
- $RegROPath = "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]"
- $TheUserName = $DefaultUsername
- $TheUserPass = $DefaultPassword
- $TheDomain = $DefaultDomain
- $TheRunAsUserName = $RunAsUsername
- $TheRunAsUserPass = $RunAsPassword
- }
- PROCESS
- {
- TRY
- {
- IF (!$AutoLogonCount) { $AutoLogonCount = 1 }
- $AALC = @"
- "AutoAdminLogon"="$AutoLogonCount"
- "@
- $DefDomDefUN = @"
- "DefaultUsername"="$DefaultDomain\\$DefaultUsername"
- "@
- $DFPW = @"
- "DefaultPassword"="$DefaultPassword"
- "@
- $RunScript = @"
- @="$Script"
- "@
- $header = "Windows Registry Editor Version 5.00`r`n`r`n"
- $header | Out-File -FilePath 'C:\Windows\Temp\LogOn.reg' -Force
- $header | Out-File -FilePath 'C:\Windows\Temp\RunOnce.reg' -Force
- Add-Content -Path 'C:\Windows\Temp\LogOn.reg' -Value "$RegPath" -Force
- Add-Content -Path 'C:\Windows\Temp\LogOn.reg' -Value $AALC -Force
- Add-Content -Path 'C:\Windows\Temp\LogOn.reg' -Value $DefDomDefUN -Force
- Add-Content -Path 'C:\Windows\Temp\LogOn.reg' -Value $DFPW -Force
- Add-Content -Path 'C:\Windows\Temp\RunOnce.reg' -Value "$RegROPath" -Force
- IF ($Script) { Add-Content -Path 'C:\Windows\Temp\RunOnce.reg' -Value $RunScript -Force }
- ELSE { Add-Content -Path 'C:\Windows\Temp\RunOnce.reg' -Value '' -Force }
- }
- CATCH { Add-Logs "Error setting required registry keys!`r`n`r`n$($_)"; $Global:BlastOff = $false }
- FINALLY
- {
- IF (!$BlastOff)
- {
- $Uzer = "$TheDomain\$TheRunAsUserName"
- $null = Runas /noprofile /user:$Uzer "reg.exe import C:\Windows\Temp\LogOn.reg"
- $null = Runas /noprofile /user:$Uzer "reg.exe import C:\Windows\Temp\RunOnce.reg"
- }
- }
- }
- END {<#End#> }
- }
- FUNCTION Set-FirstScript
- {
- TRY
- {
- $N0 = @'
- #----------------------------------------------
- # Generated Form Function
- #----------------------------------------------
- function Show-profmigExportScript1_psf {
- #----------------------------------------------
- #region Import the Assemblies
- #----------------------------------------------
- [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
- [void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
- [void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
- #endregion Import Assemblies
- #----------------------------------------------
- #region Generated Form Objects
- #----------------------------------------------
- [System.Windows.Forms.Application]::EnableVisualStyles()
- $form1 = New-Object 'System.Windows.Forms.Form'
- $richtextbox1 = New-Object 'System.Windows.Forms.RichTextBox'
- $timer1 = New-Object 'System.Windows.Forms.Timer'
- $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
- #endregion Generated Form Objects
- #----------------------------------------------
- # User Generated Script
- #----------------------------------------------
- FUNCTION Set-AutoLogon
- {
- [CmdletBinding()]
- Param (
- [Parameter(Mandatory = $True, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [String[]]$DefaultUsername,
- [Parameter(Mandatory = $True, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [String[]]$DefaultPassword,
- [Parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [AllowEmptyString()]
- [string]$DefaultDomain,
- [Parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [AllowEmptyString()]
- [String[]]$AutoLogonCount,
- [Parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [AllowEmptyString()]
- [String[]]$Script
- )
- BEGIN
- {
- #Registry path declaration
- $RegPath = "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]"
- $RegROPath = "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]"
- }
- PROCESS
- {
- TRY
- {
- IF (!$AutoLogonCount) { $AutoLogonCount = 1 }
- $AALC = @"
- "AutoAdminLogon"="$AutoLogonCount"
- "@
- $DefDomDefUN = @"
- "DefaultUsername"="$DefaultDomain\\$DefaultUsername"
- "@
- $DFPW = @"
- "DefaultPassword"="$DefaultPassword"
- "@
- $RunScript = @"
- @="$Script"
- "@
- $header = "Windows Registry Editor Version 5.00`r`n`r`n"
- $header | Out-File -FilePath 'C:\Windows\Temp\LogOn.reg' -Force
- $header | Out-File -FilePath 'C:\Windows\Temp\RunOnce.reg' -Force
- Add-Content -Path 'C:\Windows\Temp\LogOn.reg' -Value "$RegPath" -Force
- Add-Content -Path 'C:\Windows\Temp\LogOn.reg' -Value $AALC -Force
- Add-Content -Path 'C:\Windows\Temp\LogOn.reg' -Value $DefDomDefUN -Force
- Add-Content -Path 'C:\Windows\Temp\LogOn.reg' -Value $DFPW -Force
- Add-Content -Path 'C:\Windows\Temp\RunOnce.reg' -Value "$RegROPath" -Force
- IF ($Script) { Add-Content -Path 'C:\Windows\Temp\RunOnce.reg' -Value $RunScript -Force }
- ELSE { Add-Content -Path 'C:\Windows\Temp\RunOnce.reg' -Value '' -Force }
- }
- CATCH { Add-Logs "Error setting required registry keys!`r`n`r`n$($_)"; $Global:BlastOff = $false }
- FINALLY
- {
- IF (!$BlastOff)
- {
- $R1A = "import C:\Windows\Temp\LogOn.reg"
- $R2A = "import C:\Windows\Temp\RunOnce.reg"
- Start-Process -FilePath 'C:\Windows\System32\reg.exe' -ArgumentList $R1A
- Start-Process -FilePath 'C:\Windows\System32\reg.exe' -ArgumentList $R2A
- }
- }
- }
- END {<#End#> }
- }
- FUNCTION Add-Text ($Text)
- {
- $richtextbox1.Text = ''
- $richtextbox1.Text = 'Waiting 3 minutes to restart local computer.
- *** YOU MAY PRESS Q TO REBOOT IMMEDIATELY!***'
- $richtextbox1.Text += ""
- $richtextbox1.Text += "$Text"
- }
- $richtextbox1_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{
- #Event Argument: $_ = [System.Windows.Forms.KeyPressEventArgs]
- if ($_.KeyChar -eq 'q' -or $_.KeyChar -eq 'Q')
- {
- Add-Text "Rebooting now"
- Start-Sleep 1
- Restart-Computer
- }
- }
- $form1_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{
- #Event Argument: $_ = [System.Windows.Forms.KeyPressEventArgs]
- if ($_.KeyChar -eq 'q' -or $_.KeyChar -eq 'Q')
- {
- Add-Text "Rebooting now"
- Start-Sleep 1
- Restart-Computer
- }
- }
- $timer1_Tick={
- $form1.Refresh()
- $CT = $stopwatch.elapsed
- Add-Text $([string]::Format("`rTime: {0:d2}:{1:d2}:{2:d2}",
- $CT.hours,
- $CT.minutes,
- $CT.seconds))
- IF ($stopwatch.elapsed.minutes -eq 3)
- {
- Add-Text 'Restarting computer now...'
- Restart-Computer
- }
- }
- $form1_Load = {
- $Global:stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
- $timer1.Start()
- '@
- $N0 += @"
- Set-AutoLogon -DefaultUsername "$($tbServiceCredsUN.Text)" -DefaultPassword "$($mtbServiceCredsPW.Text)" -DefaultDomain "$($tbDomainToJoin.Text)" -Script 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Temp\S2.ps1 -ExecutionPolicy Unrestricted'
- }
- "@
- $N0 += @'
- # --End User Generated Script--
- #----------------------------------------------
- #region Generated Events
- #----------------------------------------------
- $Form_StateCorrection_Load=
- {
- #Correct the initial state of the form to prevent the .Net maximized form issue
- $form1.WindowState = $InitialFormWindowState
- }
- $Form_Cleanup_FormClosed=
- {
- #Remove all event handlers from the controls
- try
- {
- $stopwatch.Stop()
- $richtextbox1.remove_KeyPress($richtextbox1_KeyPress)
- $form1.remove_Load($form1_Load)
- $form1.remove_KeyPress($form1_KeyPress)
- $timer1.remove_Tick($timer1_Tick)
- $form1.remove_Load($Form_StateCorrection_Load)
- $form1.remove_FormClosed($Form_Cleanup_FormClosed)
- }
- catch { Out-Null <# Prevent PSScriptAnalyzer warning #> }
- }
- #endregion Generated Events
- #----------------------------------------------
- #region Generated Form Code
- #----------------------------------------------
- $form1.SuspendLayout()
- #
- # form1
- #
- $form1.Controls.Add($richtextbox1)
- $form1.AutoScaleDimensions = '6, 13'
- $form1.AutoScaleMode = 'Font'
- $form1.ClientSize = '554, 396'
- $form1.FormBorderStyle = 'None'
- $form1.MinimizeBox = $False
- $form1.Name = 'form1'
- $form1.ShowIcon = $False
- $form1.StartPosition = 'WindowsDefaultBounds'
- $form1.Text = 'Form'
- $form1.WindowState = 'Maximized'
- $form1.add_Load($form1_Load)
- $form1.add_KeyPress($form1_KeyPress)
- #
- # richtextbox1
- #
- $richtextbox1.Anchor = 'Top, Bottom, Left, Right'
- $richtextbox1.Location = '12, 12'
- $richtextbox1.Name = 'richtextbox1'
- $richtextbox1.ReadOnly = $True
- $richtextbox1.Size = '530, 372'
- $richtextbox1.TabIndex = 0
- $richtextbox1.Text = ''
- $richtextbox1.add_KeyPress($richtextbox1_KeyPress)
- #
- # timer1
- #
- $timer1.Interval = 1000
- $timer1.add_Tick($timer1_Tick)
- $form1.ResumeLayout()
- #endregion Generated Form Code
- #----------------------------------------------
- #Save the initial state of the form
- $InitialFormWindowState = $form1.WindowState
- #Init the OnLoad event to correct the initial state of the form
- $form1.add_Load($Form_StateCorrection_Load)
- #Clean up the control events
- $form1.add_FormClosed($Form_Cleanup_FormClosed)
- #Show the Form
- return $form1.ShowDialog()
- } #End Function
- #Call the form
- Show-profmigExportScript1_psf | Out-Null
- '@
- $N0 | Out-File 'C:\Windows\Temp\S1.ps1' -Force
- Start-Sleep -Milliseconds 200
- $SetS1 = $true
- }
- CATCH
- {
- $IVP = @{
- 'Title' = 'Error!'
- 'Message' = 'Error exporting Staging Script #1'
- 'IconType' = 'Error'
- 'ButtonType' = 'OK'
- }
- Invoke-PopUp @IVP
- Add-Logs 'Error exporting Staging Script #1'
- $SetS1 = $false
- }
- FINALLY
- {
- IF ($SetS1 -eq $true)
- {
- Add-Logs 'Successfully exported Staging Script #1.'
- }
- }
- }
- FUNCTION Set-SecondScript
- {
- TRY
- {
- $SourceProfile = $env:USERPROFILE
- $DestinationProfile = "C:\Users\$($tbDomainUsernameDEST.Text)\"
- $N1 = @'
- #----------------------------------------------
- # Generated Form Function
- #----------------------------------------------
- function Show-profmig_psf {
- #----------------------------------------------
- #region Import the Assemblies
- #----------------------------------------------
- [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
- [void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
- [void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
- #endregion Import Assemblies
- #----------------------------------------------
- #region Generated Form Objects
- #----------------------------------------------
- [System.Windows.Forms.Application]::EnableVisualStyles()
- $form1 = New-Object 'System.Windows.Forms.Form'
- $richtextbox1 = New-Object 'System.Windows.Forms.RichTextBox'
- $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
- #endregion Generated Form Objects
- #----------------------------------------------
- # User Generated Script
- #----------------------------------------------
- '@
- $N1 += @'
- FUNCTION Set-AutoLogon
- {
- [CmdletBinding()]
- Param (
- [Parameter(Mandatory = $True, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [String[]]$DefaultUsername,
- [Parameter(Mandatory = $True, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [String[]]$DefaultPassword,
- [Parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [AllowEmptyString()]
- [string]$DefaultDomain,
- [Parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [AllowEmptyString()]
- [String[]]$AutoLogonCount,
- [Parameter(Mandatory = $False, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
- [AllowEmptyString()]
- [String[]]$Script
- )
- BEGIN
- {
- #Registry path declaration
- $RegPath = "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]"
- $RegROPath = "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]"
- }
- PROCESS
- {
- TRY
- {
- IF (!$AutoLogonCount) { $AutoLogonCount = 1 }
- $AALC = @"
- "AutoAdminLogon"="$AutoLogonCount"
- "@
- $DefDomDefUN = @"
- "DefaultUsername"="$DefaultDomain\\$DefaultUsername"
- "@
- $DFPW = @"
- "DefaultPassword"="$DefaultPassword"
- "@
- $RunScript = @"
- @="$Script"
- "@
- $header = "Windows Registry Editor Version 5.00`r`n`r`n"
- $header | Out-File -FilePath 'C:\Windows\Temp\LogOn.reg' -Force
- $header | Out-File -FilePath 'C:\Windows\Temp\RunOnce.reg' -Force
- Add-Content -Path 'C:\Windows\Temp\LogOn.reg' -Value "$RegPath" -Force
- Add-Content -Path 'C:\Windows\Temp\LogOn.reg' -Value $AALC -Force
- Add-Content -Path 'C:\Windows\Temp\LogOn.reg' -Value $DefDomDefUN -Force
- Add-Content -Path 'C:\Windows\Temp\LogOn.reg' -Value $DFPW -Force
- Add-Content -Path 'C:\Windows\Temp\RunOnce.reg' -Value "$RegROPath" -Force
- IF ($Script) { Add-Content -Path 'C:\Windows\Temp\RunOnce.reg' -Value $RunScript -Force }
- ELSE { Add-Content -Path 'C:\Windows\Temp\RunOnce.reg' -Value '' -Force }
- }
- CATCH { Add-Logs "Error setting required registry keys!`r`n`r`n$($_)"; $Global:BlastOff = $false }
- FINALLY
- {
- IF (!$BlastOff)
- {
- $R1A = "import C:\Windows\Temp\LogOn.reg"
- $R2A = "import C:\Windows\Temp\RunOnce.reg"
- Start-Process -FilePath 'C:\Windows\System32\reg.exe' -ArgumentList $R1A
- Start-Process -FilePath 'C:\Windows\System32\reg.exe' -ArgumentList $R2A
- }
- }
- }
- END {<#End#> }
- }
- FUNCTION Invoke-PopUp
- {
- [CMDLETBINDING()]
- PARAM (
- [Parameter(Mandatory = $true, Position = 0)]
- [string]$Title,
- [Parameter(Mandatory = $true, Position = 1)]
- [string]$Message,
- [PARAMETER(Mandatory = $true, Position = 2)]
- [ValidateSet(
- 'Asterisk',
- 'Error',
- 'Exclamation',
- 'Hand',
- 'Information',
- 'None',
- 'Question',
- 'Stop',
- 'Warning')]
- [string]$IconType,
- [PARAMETER(Mandatory = $false, Position = 3)]
- [ValidateSet(
- 'AbortRetryIgnore',
- 'OK',
- 'OKCancel',
- 'RetryCancel',
- 'YesNo',
- 'YesNoCancel'
- )]
- [string]$ButtonType
- )
- [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
- $m = [Windows.Forms.MessageBox]::Show($Message, $Title, [Windows.Forms.MessageBoxButtons]::$ButtonType, [Windows.Forms.MessageBoxIcon]::$IconType)
- return $m
- }
- '@
- $N1 += @'
- FUNCTION Migrate-Profile
- {
- $GCI = @()
- '@
- $N1 += @"
- Get-ChildItem -Path "$($SourceProfile)" -File | ForEach-Object {
- Copy-Item $_ -Destination "$($DestinationProfile)" -Recurse -Container -PassThru;
- "@
- $N1 += @'
- Write-Host "Processing: $($_.Name)"
- }
- '@
- $N1 += @"
- Get-ChildItem -Path "$($SourceProfile)" -Directory | ForEach-Object {
- "@
- $N1 += @'
- Write-Host "Found Root Directory: $($_.FullName)"
- $GCI += $_
- }
- $GCI | ForEach-Object {
- Copy-Item $_ -Destination `
- '@
- $N1 += @"
- "$($DestinationProfile)" -Recurse -Container -PassThru | Select-Object -ExpandProperty Fullname | ForEach-Object {
- "@
- $N1 += @'
- Write-Host "Processing: "$_
- }
- }
- }
- $richtextbox1_TextChanged={
- $richtextbox1.SelectionStart = $richtextbox1.Text.Length
- $richtextbox1.ScrollToCaret()
- }
- $form1_Load = {
- '@
- $N1 += @"
- Set-AutoLogon -DefaultUsername "$($tbDomainUsernameDEST.Text)" -DefaultPassword "$($mtbDomainPasswordDEST.Text)" -DefaultDomain "$($tbDomainToJoin.Text)"
- "@
- $N1 += @'
- Migrate-Profile
- Invoke-PopUp -Title 'Completed Operation' -Message 'Press OK to finalize process, and boot into destination account profile.' -IconType Informational -ButtonType OK
- }
- '@
- $N1 += @'
- # --End User Generated Script--
- #----------------------------------------------
- #region Generated Events
- #----------------------------------------------
- $Form_StateCorrection_Load=
- {
- #Correct the initial state of the form to prevent the .Net maximized form issue
- $form1.WindowState = $InitialFormWindowState
- }
- $Form_Cleanup_FormClosed=
- {
- #Remove all event handlers from the controls
- try
- {
- $form1.remove_Load($form1_Load)
- $form1.remove_Load($Form_StateCorrection_Load)
- $form1.remove_FormClosed($Form_Cleanup_FormClosed)
- }
- catch { Out-Null <# Prevent PSScriptAnalyzer warning #> }
- }
- #endregion Generated Events
- #----------------------------------------------
- #region Generated Form Code
- #----------------------------------------------
- $form1.SuspendLayout()
- #
- # form1
- #
- $form1.Controls.Add($richtextbox1)
- $form1.AutoScaleDimensions = '6, 13'
- $form1.AutoScaleMode = 'Font'
- $form1.ClientSize = '675, 533'
- $form1.FormBorderStyle = 'None'
- $form1.MinimizeBox = $False
- $form1.Name = 'form1'
- $form1.ShowIcon = $False
- $form1.ShowInTaskbar = $False
- $form1.StartPosition = 'WindowsDefaultBounds'
- $form1.Text = 'Form'
- $form1.WindowState = 'Maximized'
- $form1.add_Load($form1_Load)
- #
- # richtextbox1
- #
- $richtextbox1.Location = '13, 12'
- $richtextbox1.Anchor = 'Top, Bottom, Left, Right'
- $richtextbox1.Name = 'richtextbox1'
- $richtextbox1.ReadOnly = $True
- $richtextbox1.Size = '650, 509'
- $richtextbox1.TabIndex = 0
- $richtextbox1.Text = ''
- $form1.ResumeLayout()
- #endregion Generated Form Code
- #----------------------------------------------
- #Save the initial state of the form
- $InitialFormWindowState = $form1.WindowState
- #Init the OnLoad event to correct the initial state of the form
- $form1.add_Load($Form_StateCorrection_Load)
- #Clean up the control events
- $form1.add_FormClosed($Form_Cleanup_FormClosed)
- #Show the Form
- return $form1.ShowDialog()
- } #End Function
- #Call the form
- Show-profmig_psf | Out-Null
- '@
- $N1 | Out-File -FilePath "C:\Windows\Temp\S2.ps1" -Force
- $SetAL2 = $true
- }
- CATCH
- {
- $ILP = @{
- 'Title' = 'Error!'
- 'Message' = "Error exporting Staging Script #2 $($_)"
- 'IconType' = 'Error'
- 'ButtonType' = 'OK'
- }
- Invoke-PopUp @ILP
- Add-Logs 'Error exporting Staging Script #2'
- $SetAL2 = $false
- }
- FINALLY
- {
- IF ($SetAL2 -eq $true)
- {
- Add-Logs 'Successfully exported Staging Script #2.'
- }
- }
- }
- #endregion FORM FUNCTIONS
- #region FORM MAIN
- $btnOK_Click = {
- IF (!$BlastOff) { $Script:BlastOff = 'Go' }
- $MTB = [System.Windows.Forms.MaskedTextBox]
- $RTB = [System.Windows.Forms.TextBox]
- $RCB = [System.Windows.Forms.ComboBox]
- $RGB = [System.Windows.Forms.GroupBox]
- FOREACH ($RGB in $MainForm.Controls)
- {
- FOREACH ($MTB in $RGB.Controls)
- {
- IF ($MTB.Text -eq $null -or $MTB.Text -eq "") { $BlastOff = $false }
- }
- FOREACH ($RTB in $RGB.Controls)
- {
- IF ($RTB.Text -eq $null -or $RTB.Text -eq "") { $BlastOff = $false }
- }
- FOREACH ($RCB in $RGB.Controls)
- {
- IF ($RCB.Text -eq $null -or $RCB.Text -eq "") { $BlastOff = $false }
- }
- }
- IF ($BlastOff -eq $false)
- {
- $IPP = @{
- 'Title' = 'Error!'
- 'Message' = 'Please fill out empty fields.'
- 'IconType' = 'Exclamation'
- 'ButtonType' = 'OK'
- }
- Invoke-PopUp @IPP
- Add-Logs 'Please fill out empty fields'
- }
- IF ($BlastOff -eq 'Go')
- {
- TRY
- {
- [string]$Global:DOMA = $tbDomainToJoin.Text
- [string]$Global:PTUN = $tbServiceCredsUN.Text
- [string]$Global:PassPass = $mtbServiceCredsPW.Text
- $Global:FinalPW = $PassPass | ConvertTo-SecureString -AsPlainText -Force
- [string]$Global:FinalUN = "$DOMA\$PTUN"
- $Global:svcCrds = New-Object System.Management.Automation.PSCredential($FinalUN, $FinalPW)
- Start-Sleep -Milliseconds 200
- Add-Logs 'Exporting required files...'
- Set-FirstScript
- Start-Sleep -Milliseconds 200
- Set-SecondScript
- $SIPsplat = @{
- 'Path' = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
- 'Name' = 'EnableFirstLogonAnimation'
- 'Type' = 'DWORD'
- 'Value' = 0
- 'Force' = $true
- }
- Set-ItemProperty @SIPsplat | Out-Null
- Start-Sleep -Milliseconds 200
- Add-Logs 'Finished exporting required files...'
- Start-Sleep -Milliseconds 100
- Add-Logs 'Configuring auto logon for next boot..'
- Set-AutoLogon -DefaultUsername $($tbDomainUsernameDEST.Text) -DefaultPassword $($mtbDomainPasswordDEST.Text) -DefaultDomain $($tbDomainToJoin.Text) -AutoLogonCount 1 -Script 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\Windows\Temp\S1.ps1 -ExecutionPolicy Unrestricted'
- Start-Sleep -Milliseconds 200
- Add-Logs 'Joining machine to domain...'
- Add-Computer -DomainName $($tbDomainToJoin.Text) -Credential $svcCrds -ErrorAction Stop -WarningAction SilentlyContinue -ErrorVariable ErrorJoiningMachineToDomain
- IF (!$ErrorJoiningMachineToDomain) { $cont = $true; Add-Logs 'Successfully joined domain!' }
- }
- CATCH
- {
- Invoke-PopUp -Title 'Error!' -Message "Encountered Error!`r`n`r`n$($_)" -IconType Error -ButtonType OK
- Add-Logs 'Error joining localhost to domain!'
- $cont = $false
- }
- FINALLY
- {
- IF ($cont -eq $true)
- {
- $reboot = Invoke-PopUp -Title 'Warning' -Message 'Please select OK to reboot.' -IconType Information -ButtonType OKCancel
- SWITCH ($reboot)
- {
- 'OK' { Restart-Computer }
- 'Cancel' { <# DO NOTHING #> }
- }
- }
- }
- }
- }
- $rtbLogs_TextChanged = {
- $rtbLogs.SelectionStart = $rtbLogs.Text.Length
- $rtbLogs.ScrollToCaret()
- }
- $tbDomainUsernameDEST_TextChanged = {
- IF ($tbDomainUsernameDEST.Text -like "*\*")
- {
- $b = Invoke-PopUp -Title 'Stop' -Message "Only username is needed, do not enter a domain. `r`n| GOOD = john.smith |`r`n| BAD = domain\john.smith |" -IconType Stop -ButtonType OK
- Add-Logs 'Only username is needed, do not enter a domain.'
- SWITCH ($b) { 'OK' { $tbDomainUsernameDEST.Text = "" } }
- }
- }
- $tbServiceCredsUN_TextChanged = {
- IF ($tbServiceCredsUN.Text -like "*\*")
- {
- $g = Invoke-PopUp -Title 'Stop' -Message "Only username is needed, do not enter a domain. `r`n| GOOD = john.smith |`r`n| BAD = domain\john.smith |" -IconType Stop -ButtonType OK
- Add-Logs 'Only username is needed, do not enter a domain.'
- SWITCH ($g) { 'OK' { $tbServiceCredsUN.Text = "" } }
- }
- }
- #endregion FORM MAIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement