Advertisement
aussierob78

Imaging - Reddit

Mar 13th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Image deployment script
  2.  
  3. # Get the ID and security principal of the current user account
  4. $myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
  5. $myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
  6.  
  7. # Get the security principal for the Administrator role
  8. $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
  9.  
  10. # Check privledges
  11. if ($myWindowsPrincipal.IsInRole($adminRole))
  12.    {
  13.    # Change window title and background colour to indicate admin rights
  14.    $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
  15.    $Host.UI.RawUI.BackgroundColor = "Red"
  16.    clear-host
  17.    }
  18. else
  19.    {
  20.    # If not currently running as an admin, restart with admin privledges
  21.    
  22.    $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
  23.    
  24.    $newProcess.Arguments = $myInvocation.MyCommand.Definition;
  25.    
  26.    $newProcess.Verb = "runas";
  27.    
  28.    [System.Diagnostics.Process]::Start($newProcess);
  29.    
  30.    # Exit from the current, unelevated process
  31.    exit
  32.    }
  33.  
  34. # Imaging script. Please modify for your own site
  35.  
  36. # This section resets the WDSSERVER service and boot images
  37. [BOOLEAN]$global:xExitSession=$false
  38. import-module IntelvPro
  39. $amtcred = Read-AmtCredential
  40. CLS
  41. write-host "Starting service and disabling boot images" -ForegroundColor Green
  42. $swcount = "-N"
  43. net start wdsserver | Out-Null
  44. Disable-WdsBootImage -Architecture x64 -ImageName "Multicast WDS" | Out-Null
  45. Disable-WdsBootImage -Architecture x86 -Imagename "Image C and D Reboot" | Out-Null
  46. Disable-WDSBootImage -Architecture X86 -ImageName "Image C Reboot" | Out-Null
  47. Disable-WdsBootImage -Architecture X86 -ImageName "Image D Reboot" | Out-Null
  48. Disable-WdsBootImage -Architecture X86 -ImageName "Ghost32 (Capture)" | Out-Null
  49. Disable-WdsBootImage -Architecture X86 -ImageName "CleanDisks image c reboot" | Out-Null
  50. CLS
  51.  
  52. # User input requested for image selection and lab choice
  53. write-host "Please select a ghost image" -ForegroundColor Yellow
  54. while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 8 ) {
  55. write-host "`t`t`t1. DWT Windows 8 & Office 2010" -Fore Cyan
  56. write-host "`t`t`t2. DWT Windows 8 & Office 2013" -ForegroundColor Cyan
  57. write-host "`t`t`t3. Windows 7 & Office 2010 (Dell)" -ForegroundColor Cyan
  58. write-host "`t`t`t4. Windows 8 & Office 2010 (Dell)" -Fore Cyan
  59. write-host "`t`t`t5. Windows 7 & Office 2010 (ThermalTake)" -ForegroundColor Cyan
  60. write-host "`t`t`t6. Windows 8 & Office 2010 (ThermalTake)" -ForegroundColor Cyan
  61. write-host "`t`t`t7. Generic image" -ForegroundColor Cyan
  62. write-host "`t`t`t8. MSFT test image" -ForegroundColor Cyan
  63. write-host " "
  64. [int] $xMenuChoiceA = read-host "Please select option 1 to 8..." }
  65. CLS
  66.  
  67. # This next step can be removed if you want to set the number of computers as fixed. Make sure you update the ghost command line section below
  68.  
  69. Write-Host " "
  70. $count = Read-Host "How many machines require ghosting?"
  71. CLS
  72. write-host "Please select a Lab" -ForegroundColor Yellow
  73. while ( $xMenuChoiceB -lt 1 -or $xMenuChoiceB -gt 4 ) {
  74. write-host "`t`t`t1. Lab 1.5" -Fore Cyan
  75. write-host "`t`t`t2. Lab 1.6 - High Spec Lab" -ForegroundColor Cyan
  76. write-host "`t`t`t3. Lab 1.7 - High Spec Lab" -ForegroundColor Cyan
  77. write-host "`t`t`t4. Lab 1.8" -Foregroundcolor Cyan
  78. write-host " "
  79. [int] $xMenuChoiceB = read-host "Please select option 1 to 4..."}
  80. # User inputs are injected into the commands below, to start the Ghostcast session
  81. Switch ( $xMenuChoiceA ) {
  82. 1{ Enable-WdsBootImage -Architecture x86 -Imagename "Image C Reboot"; c:\ghost\GhostSrv.exe "\\server details\filepath\ghostfile.gho" 1 $swcount$count -C -LE -FC:\Scripts\Logs\Ghost.log }
  83. 2{ Enable-WdsBootImage -Architecture x86 -Imagename "Image C Reboot"; c:\ghost\GhostSrv.exe "\\server details\filepath\ghostfile.gho" 1 $swcount$count -C -LE -FC:\Scripts\Logs\Ghost.log }
  84. 3{ Enable-WdsBootImage -Architecture x86 -Imagename "Image C Reboot"; c:\ghost\GhostSrv.exe "\\server details\filepath\ghostfile.gho" 1 $swcount$count -C -LE -FC:\Scripts\Logs\Ghost.log }
  85. 4{ Enable-WdsBootImage -Architecture x86 -Imagename "Image C Reboot"; c:\ghost\GhostSrv.exe "\\server details\filepath\ghostfile.gho" 1 $swcount$count -C  -LE -FC:\Scripts\Logs\Ghost.log }
  86. 5{ Enable-WdsBootImage -Architecture x86 -Imagename "Image C Reboot"; c:\ghost\GhostSrv.exe "\\server details\filepath\ghostfile.gho" 1 $swcount$count -C -LE -FC:\Scripts\Logs\Ghost.log }
  87. 6{ Enable-WdsBootImage -Architecture x86 -Imagename "Image C Reboot"; c:\ghost\GhostSrv.exe "\\server details\filepath\ghostfile.gho" 1 $swcount$count -C -LE -FC:\Scripts\Logs\Ghost.log }
  88. 7{ Enable-WdsBootImage -Architecture x86 -Imagename "Image C Reboot"; c:\ghost\GhostSrv.exe "\\server details\filepath\ghostfile.gho" 1 $swcount$count -C -LE -FC:\Scripts\Logs\Ghost.log }
  89. 8{ Enable-WdsBootImage -Architecture x86 -Imagename "Image C and D Reboot"; c:\ghost\GhostSrv.exe "\\server details\filepath\ghostfile.gho" 1 $swcount$count -C -LE; c:\ghost\GhostSrv.exe "\\server details\filepath\ghostfile d drive.gho" 2 $swcount$count -C -LE -FC:\Scripts\Logs\Ghost.log }
  90.  
  91. }
  92. # Switches are changed to deployment vlan, computers are powered on and instructed to PXE boot. Script sleeps, disables WDSSERVER service, waits and then continues
  93. Switch ( $xMenuChoiceB ) {
  94. 1{ perl c:\scripts\perl\Lab15_Vlan4.pl; get-content c:\scripts\labs\lab15.txt | Invoke-AMTForceBoot -Device PXE -Operation PowerOn -Credential $amtcred; write-host "Imaging in progress..."; $a = get-process Ghostsrv; $a.WaitForExit(); write-host "Program Closed"; net stop wdsserver; write-host "WDS Service Stopped" }
  95. 2{ perl C:\Scripts\perl\Lab16_Vlan4.pl; get-content c:\scripts\labs\lab16.txt | Invoke-AMTForceBoot -Device PXE -Operation PowerOn -Credential $amtcred; write-host "Imaging in progress..."; $a = get-process Ghostsrv; $a.WaitForExit(); write-host "Program Closed"; net stop wdsserver; write-host "WDS Service Stopped" }
  96. 3{ perl C:\Scripts\Perl\Lab17_Vlan4.pl; get-content c:\scripts\labs\lab17.txt | Invoke-AMTForceBoot -Device PXE -Operation PowerOn -Credential $amtcred; write-host "Imaging in progress..."; $a = get-process Ghostsrv; $a.WaitForExit(); write-host "Program Closed"; net stop wdsserver; write-host "WDS Service Stopped" }
  97. 4{ perl C:\Scripts\perl\Lab18_Vlan4.pl; get-content c:\scripts\labs\lab18.txt | Invoke-AMTForceBoot -Device PXE -Operation PowerOn -Credential $amtcred; write-host "Imaging in progress..."; $a = get-process Ghostsrv; $a.WaitForExit(); write-host "Program Closed"; net stop wdsserver; write-host "WDS Service Stopped" }
  98. }
  99.  
  100. # Email alerts are generated, and the ghost.log is added as an attachment. The content is also extracted and sent in the body of the email.
  101. $SMTPServer = "smtp.gmail.com"
  102. $SMTPPort = "587"
  103. $Username = "@gmail.com"
  104. $Password = ""
  105. $file = "C:\scripts\logs\ghost.log"
  106. $to = ""
  107. $subject = "Lab Imaging Complete"
  108. $body = get-content C:\Scripts\Logs\ghost.log
  109. $att = New-Object Net.Mail.Attachment ($file)
  110.  
  111. $message = New-Object System.Net.Mail.MailMessage
  112. $message.subject = $subject
  113. $message.body = $body
  114. $message.to.add($to)
  115. $message.from = $username
  116.  
  117. $smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
  118. $smtp.EnableSSL = $true
  119. $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
  120. $message.Attachments.Add($att)
  121. $smtp.send($message)
  122. write-host "Mail Sent"
  123.  
  124. # Android alert notifications are generated, and the ghost.log file is injected into the notification
  125. # Alternative services such as Pushover.net can accomodate devices other than android
  126. # param ($server, $shortname, $status, $datetime, $group, $prioritytext, $down, $message, $lastvalue)
  127. $server = get-content env:computername
  128. $datetime =  get-date -DisplayHint DateTime -Format G
  129. $status = Get-Content C:\Scripts\Logs\ghost.log
  130.  
  131. # This is the unique API Key associated with my account
  132. # $nmaurl = 'https://www.notifymyandroid.com/publicapi/notify'
  133. # $nmaapikey = 'api key goes here'
  134.  
  135. # The priority can be changed from -2 (very low) up to 2 (emergency). 0 is Normal
  136. #$priority = [regex]::matches($prioritytext,"\*").Count
  137. #priority = $priority-0
  138.  
  139. # This defines the message sent
  140. # $parameters = 'apikey=' + $nmaapikey + '&application=PRTG&event=' + $server + ' ' + $shortname + ' ' + $status + '&description=' + $datetime + ' ' + $group + ' Last value: ' + $lastvalue + '&priority=' + $priority
  141. #$http2 = New-Object -ComObject Msxml2.XMLHTTP
  142. #$http2.open('POST', $nmaurl, $false)
  143. #$http2.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
  144. #$http2.setRequestHeader("Content-length", $parameters.length)
  145. #$http2.setRequestHeader("Connection", "close")
  146. #$http2.send($parameters)
  147. #$http2.statusText
  148.  
  149. #iphone section - this will send the ghost log in a notification
  150. import-module ps-pushover
  151. $token = 'token here'
  152. $user = 'api key here'
  153. Send-PushoverMessage -title "Deployment Complete" -message $body -sound "gamelan" -token $token -user $user
  154.  
  155. # Ghost.log is renamed according to current date/time for future reference
  156. # C:\scripts\ps\Stamp.ps1 C:\scripts\logs\ghost.log
  157. # Starts a 30 minute delay, then changes the vlan back from deployment
  158. write-host "Beginning 30 minute wait prior to vlan reset"
  159. Switch ( $xMenuChoiceB ) {
  160. 1{ start-sleep -s 1800; perl C:\Scripts\Perl\Lab15_Vlan5.pl }
  161. 2{ start-sleep -s 1800; perl C:\Scripts\Perl\Lab16_Vlan6.pl }
  162. 3{ Start-Sleep -s 1800; perl C:\Scripts\Perl\Lab17_Vlan7.pl }
  163. 4{ Start-sleep -s 1800; perl C:\Scripts\perl\Lab18_Vlan8.pl }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement