Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Image deployment script
- # Get the ID and security principal of the current user account
- $myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
- $myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
- # Get the security principal for the Administrator role
- $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
- # Check privledges
- if ($myWindowsPrincipal.IsInRole($adminRole))
- {
- # Change window title and background colour to indicate admin rights
- $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
- $Host.UI.RawUI.BackgroundColor = "Red"
- clear-host
- }
- else
- {
- # If not currently running as an admin, restart with admin privledges
- $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
- $newProcess.Arguments = $myInvocation.MyCommand.Definition;
- $newProcess.Verb = "runas";
- [System.Diagnostics.Process]::Start($newProcess);
- # Exit from the current, unelevated process
- exit
- }
- # Imaging script. Please modify for your own site
- # This section resets the WDSSERVER service and boot images
- [BOOLEAN]$global:xExitSession=$false
- import-module IntelvPro
- $amtcred = Read-AmtCredential
- CLS
- write-host "Starting service and disabling boot images" -ForegroundColor Green
- $swcount = "-N"
- net start wdsserver | Out-Null
- Disable-WdsBootImage -Architecture x64 -ImageName "Multicast WDS" | Out-Null
- Disable-WdsBootImage -Architecture x86 -Imagename "Image C and D Reboot" | Out-Null
- Disable-WDSBootImage -Architecture X86 -ImageName "Image C Reboot" | Out-Null
- Disable-WdsBootImage -Architecture X86 -ImageName "Image D Reboot" | Out-Null
- Disable-WdsBootImage -Architecture X86 -ImageName "Ghost32 (Capture)" | Out-Null
- Disable-WdsBootImage -Architecture X86 -ImageName "CleanDisks image c reboot" | Out-Null
- CLS
- # User input requested for image selection and lab choice
- write-host "Please select a ghost image" -ForegroundColor Yellow
- while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 8 ) {
- write-host "`t`t`t1. DWT Windows 8 & Office 2010" -Fore Cyan
- write-host "`t`t`t2. DWT Windows 8 & Office 2013" -ForegroundColor Cyan
- write-host "`t`t`t3. Windows 7 & Office 2010 (Dell)" -ForegroundColor Cyan
- write-host "`t`t`t4. Windows 8 & Office 2010 (Dell)" -Fore Cyan
- write-host "`t`t`t5. Windows 7 & Office 2010 (ThermalTake)" -ForegroundColor Cyan
- write-host "`t`t`t6. Windows 8 & Office 2010 (ThermalTake)" -ForegroundColor Cyan
- write-host "`t`t`t7. Generic image" -ForegroundColor Cyan
- write-host "`t`t`t8. MSFT test image" -ForegroundColor Cyan
- write-host " "
- [int] $xMenuChoiceA = read-host "Please select option 1 to 8..." }
- CLS
- # 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
- Write-Host " "
- $count = Read-Host "How many machines require ghosting?"
- CLS
- write-host "Please select a Lab" -ForegroundColor Yellow
- while ( $xMenuChoiceB -lt 1 -or $xMenuChoiceB -gt 4 ) {
- write-host "`t`t`t1. Lab 1.5" -Fore Cyan
- write-host "`t`t`t2. Lab 1.6 - High Spec Lab" -ForegroundColor Cyan
- write-host "`t`t`t3. Lab 1.7 - High Spec Lab" -ForegroundColor Cyan
- write-host "`t`t`t4. Lab 1.8" -Foregroundcolor Cyan
- write-host " "
- [int] $xMenuChoiceB = read-host "Please select option 1 to 4..."}
- # User inputs are injected into the commands below, to start the Ghostcast session
- Switch ( $xMenuChoiceA ) {
- 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 }
- 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 }
- 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 }
- 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 }
- 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 }
- 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 }
- 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 }
- 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 }
- }
- # Switches are changed to deployment vlan, computers are powered on and instructed to PXE boot. Script sleeps, disables WDSSERVER service, waits and then continues
- Switch ( $xMenuChoiceB ) {
- 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" }
- 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" }
- 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" }
- 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" }
- }
- # 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.
- $SMTPServer = "smtp.gmail.com"
- $SMTPPort = "587"
- $Username = "@gmail.com"
- $Password = ""
- $file = "C:\scripts\logs\ghost.log"
- $to = ""
- $subject = "Lab Imaging Complete"
- $body = get-content C:\Scripts\Logs\ghost.log
- $att = New-Object Net.Mail.Attachment ($file)
- $message = New-Object System.Net.Mail.MailMessage
- $message.subject = $subject
- $message.body = $body
- $message.to.add($to)
- $message.from = $username
- $smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
- $smtp.EnableSSL = $true
- $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
- $message.Attachments.Add($att)
- $smtp.send($message)
- write-host "Mail Sent"
- # Android alert notifications are generated, and the ghost.log file is injected into the notification
- # Alternative services such as Pushover.net can accomodate devices other than android
- # param ($server, $shortname, $status, $datetime, $group, $prioritytext, $down, $message, $lastvalue)
- $server = get-content env:computername
- $datetime = get-date -DisplayHint DateTime -Format G
- $status = Get-Content C:\Scripts\Logs\ghost.log
- # This is the unique API Key associated with my account
- # $nmaurl = 'https://www.notifymyandroid.com/publicapi/notify'
- # $nmaapikey = 'api key goes here'
- # The priority can be changed from -2 (very low) up to 2 (emergency). 0 is Normal
- #$priority = [regex]::matches($prioritytext,"\*").Count
- #priority = $priority-0
- # This defines the message sent
- # $parameters = 'apikey=' + $nmaapikey + '&application=PRTG&event=' + $server + ' ' + $shortname + ' ' + $status + '&description=' + $datetime + ' ' + $group + ' Last value: ' + $lastvalue + '&priority=' + $priority
- #$http2 = New-Object -ComObject Msxml2.XMLHTTP
- #$http2.open('POST', $nmaurl, $false)
- #$http2.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
- #$http2.setRequestHeader("Content-length", $parameters.length)
- #$http2.setRequestHeader("Connection", "close")
- #$http2.send($parameters)
- #$http2.statusText
- #iphone section - this will send the ghost log in a notification
- import-module ps-pushover
- $token = 'token here'
- $user = 'api key here'
- Send-PushoverMessage -title "Deployment Complete" -message $body -sound "gamelan" -token $token -user $user
- # Ghost.log is renamed according to current date/time for future reference
- # C:\scripts\ps\Stamp.ps1 C:\scripts\logs\ghost.log
- # Starts a 30 minute delay, then changes the vlan back from deployment
- write-host "Beginning 30 minute wait prior to vlan reset"
- Switch ( $xMenuChoiceB ) {
- 1{ start-sleep -s 1800; perl C:\Scripts\Perl\Lab15_Vlan5.pl }
- 2{ start-sleep -s 1800; perl C:\Scripts\Perl\Lab16_Vlan6.pl }
- 3{ Start-Sleep -s 1800; perl C:\Scripts\Perl\Lab17_Vlan7.pl }
- 4{ Start-sleep -s 1800; perl C:\Scripts\perl\Lab18_Vlan8.pl }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement