Advertisement
Guest User

MDT Setup Script

a guest
Jan 14th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. # Microsoft Deployment Toolkit - Automated Setup Script
  3. # Author: Simon Lee
  4. # Version Contol
  5. v1.0 December 2018 - Initial Script Created
  6. v1.1 January 2019 - Added MDT and ADK Insatll Dirctory Query to skip is software already installed.
  7. v1.2 ReferenceShare Inital Script Completed Added Domain Query for Service and Local Account
  8. v1.3 DeploymentShare Initial Script Created
  9. v1.3.1 Added ASCSI Slant Text and Script Title Text
  10.  
  11. #>
  12.  
  13. # Script Varibales
  14. # Microsoft Deployment Toolkit Version 6.3.8450.1000 - Pleaes update to latest version if required
  15. $MDTSource = "https://download.microsoft.com/download/3/3/9/339BE62D-B4B8-4956-B58D-73C4685FC492/MicrosoftDeploymentToolkit_x64.msi"
  16. # Windows ADK 1803 10.17134.1 - Pleaes update to latest version if required
  17. $ADKSource = "http://download.microsoft.com/download/6/8/9/689E62E5-C50F-407B-9C3C-B7F00F8C93C0/adk/adksetup.exe"
  18.  
  19. # Powershell Window Title Text
  20. $host.ui.RawUI.WindowTitle = "Microsoft Deployment Toolkit - Automated Setup Script"
  21.  
  22. # Clear Screen
  23. Clear-Host
  24.  
  25. # Source: http://patorjk.com/software/taag/#p=display&f=Slant&t=MDT%20Automated%20Setup
  26. Write-Host "      __  _______  ______   ___         __                        __           __   _____      __               " -ForegroundColor Cyan      
  27. Write-Host "     /  |/  / __ \/_  __/  /   | __  __/ /_____  ____ ___  ____ _/ /____  ____/ /  / ___/___  / /___  ______    " -ForegroundColor Cyan
  28. Write-Host "    / /|_/ / / / / / /    / /| |/ / / / __/ __ \/ __ `__  \/ __ `/  __/ _ \/ __  /   \__ \/ _ \/ __/ / / / __ \ " -ForegroundColor Cyan
  29. Write-Host "   / /  / / /_/ / / /    / ___ / /_/ / /_/ /_/ / / / / / / /_/ / /_/  __/ /_/ /   ___/ /  __/ /_/ /_/ / /_/ /   " -ForegroundColor Cyan
  30. Write-Host "  /_/  /_/_____/ /_/    /_/  |_\__,_/\__/\____/_/ /_/ /_/\__,_/\__/\___/\__,_/   /____/\___/\__/\__,_/ .___/    " -ForegroundColor Cyan
  31. Write-Host "                                                                                                     /_/        " -ForegroundColor Cyan
  32.  
  33. # Import Powershell Modules
  34. Import-Module BitsTransfer
  35. Import-Module SmbShare
  36.  
  37. Write-Host ""
  38. Write-Host "Powershell Modules Imported" -ForegroundColor Green
  39. Write-Host ""
  40.  
  41. # Query Operating System - Roles and Features
  42. $SystemType = (Get-WmiObject -Class Win32_ComputerSystem -Property DomainRole).DomainRole
  43. If ( $SystemType -eq '0' ) {
  44.     # Client Machine - Desktop or Laptop running Windows OS
  45.     Write-Host ""
  46.     Write-Host "WARNING - Windows Client Machine - Can only Support Deployment Toolkit and ADK" -ForegroundColor Yellow
  47.     Write-Host ""
  48. }
  49. If ( $SystemType -eq '1' ) {
  50.     # Standalone Workstation
  51.     Write-Host "Standalone Workstation - Doesnt support Roles and Features"  
  52.  
  53. }
  54. If ( $SystemType -eq '2' -or '3' ) {
  55.     # Standalone Workstation
  56.     $WDSRole = (Get-WindowsOptionalFeature -FeatureName Microsoft-Windows-Deployment-Services -Online).State
  57. }
  58. If ( $WDSRole -eq 'Disabled' ) {
  59.     # Role Missing - Install Role
  60.     Install-WindowsFeature -Name WDS -IncludeManagementTools
  61. }
  62.  
  63. $MDTDirectory = 'C:\Program Files\Microsoft Deployment Toolkit'
  64. $ADKDirectory = 'C:\Program Files (x86)\Windows Kits'
  65.  
  66. If ( Test-Path $MDTDirectory) {
  67.     Write-Host 'Microsoft Deployment Toolkit Detected... Skipping Install' -ForegroundColor Cyan
  68. }
  69. Else {
  70.     # Create MDT Setup Directory
  71.     Write-Host ""
  72.     Write-Host "For Example: C:\MDTSetup"
  73.     $MDTSetup = Read-Host "Please specific setup directory for install media"
  74.     New-Item -ItemType Directory -Path $MDTSetup | Out-Null
  75.  
  76.     # Microsoft Deployment Toolkit 64x - Latest Version
  77.     Start-BitsTransfer -DisplayName 'Microsoft Deployment Toolkit Downloading' -Description ' ' -Source $MDTSource -Destination $MDTSetup\MicrosoftDeploymentToolkit_x64.msi
  78.     Write-Host ""
  79.     Write-Host "MDT Download Completed"
  80.  
  81.     # Installing Micosoft Deployment Toolkit
  82.     Write-Host ""
  83.     Write-Host "Installing MDT...."
  84.     Start-Process -FilePath "$MDTSetup\MicrosoftDeploymentToolkit_x64.msi" -ArgumentList '/passive' -Wait
  85.  
  86.     Write-Host ""    
  87.     Write-Host "MDT Installation Completed" -ForegroundColor Green
  88. }
  89.  
  90. If ( Test-Path $ADKDirectory) {
  91.     Write-HOst 'Windows Assessment and Deployment Kit Detected... Skipping Install' -ForegroundColor Cyan
  92. }
  93. Else {
  94.     # Windows Assessment and Deployment Kit
  95.     Start-BitsTransfer -DisplayName 'Microsoft ADK 1803 Downloading' -Description ' ' -Source $ADKSource -Destination $MDTSetup\adksetup.exe
  96.     Write-Host ""
  97.     Write-Host "Windows ADK Download Completed"
  98.  
  99.     # Installing Windows Assessment and Deployment Kit - Silent Setup Reference: https://docs.microsoft.com/en-us/windows-hardware/get-started/adk-offline-install
  100.     Write-Host ""
  101.     Write-Host "Installing Windows ADK...."
  102.     Start-Process -FilePath "$MDTSetup\adksetup.exe"-ArgumentList '/norestart /q /ceip off /features OptionId.WindowsPreinstallationEnvironment OptionId.DeploymentTools OptionId.UserStateMigrationTool' -Wait
  103.  
  104.     Write-Host ""
  105.     Write-Host "ADK Installation Completed" -ForegroundColor Green
  106. }
  107.  
  108. # Deployment Share Provisoning Menu
  109. [int]$MDTSetupMenu = 0
  110. while ( $MDTSetupMenu -lt 1 -or $MDTSetupMenu -gt 4) {
  111.  
  112.     Write-Host ""
  113.     Write-Host "[1] MDT Reference Share"
  114.     Write-Host "[2] MDT Deployment Share"
  115.     Write-Host "[3] Quit MDT Setup Menu"
  116.     Write-Host ""
  117.  
  118.     [Int]$MDTSetupMenu = read-Host "Please select an option."
  119. }
  120. Switch ( $MDTSetupMenu ) {
  121.     1 {
  122.         # Import Microsoft Deployment Toolkit Powershell Module
  123.         Import-Module "C:\Program Files\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"    
  124.        
  125.         # Configure Directory Letter for Folder
  126.         $DriveLetter = Read-Host "Please enter a driver letter to provision the ReferenceShare"
  127.        
  128.         # Query Drive Letter and Check if Already Created - Mainly for Development within Lab Environments.
  129.         $CheckDir = "$DriveLetter\ReferenceShare"
  130.         If (Test-Path $CheckDir) {
  131.             Write-Host ""  
  132.             Write-Host "WARNING... Directory Found under: $DriveLetter\ReferenceShare" -ForegroundColor Red
  133.  
  134.             $Query = Read-Host "Do you want to reset your ReferenceShare Directory [Y] or [N]"
  135.             If ($Query -eq 'Y') {
  136.                 If ((Get-WmiObject Win32_Computersystem).partofdomain -eq $True) {
  137.                     Remove-SMBShare -Name "ReferenceShare$" -Force
  138.                     Remove-Item -Path "$DriveLetter\ReferenceShare" -Force -Recurse
  139.            
  140.                 }
  141.                 Else {
  142.                     Remove-SMBShare -Name "ReferenceShare$" -Force
  143.                     Remove-Item -Path "$DriveLetter\ReferenceShare" -Force -Recurse
  144.                     Remove-LocalUser -Name "mdt_connect"
  145.                 }  
  146.             }
  147.         }
  148.  
  149.         # Provision Deployment Work Space
  150.         New-Item -Path "$DriveLetter\ReferenceShare" -ItemType directory
  151.         New-SmbShare -Name "ReferenceShare$" -Path "$DriveLetter\ReferenceShare" -FullAccess Administrators
  152.         New-PSDrive -Name "DS001" -PSProvider "MDTProvider" -Root "$DriveLetter\ReferenceShare" -Description "MDT Reference Share" -NetworkPath "\\$env:COMPUTERNAME\ReferenceShare$" -Verbose | add-MDTPersistentDrive -Verbose
  153.         New-Item -Path "$DriveLetter\ReferenceShare\AppImport" -ItemType directory
  154.  
  155.         # Create Applications Folders
  156.         New-item -Path "DS001:\Applications" -enable "True" -Name "DeploymentBunny Scripts" -Comments "" -ItemType "folder" -Verbos
  157.         New-item -path "DS001:\Applications" -enable "True" -Name "Microsoft Applications" -Comments "" -ItemType "folder" -Verbose
  158.  
  159.         # Create Operating System Folders
  160.         New-item -path "DS001:\Operating Systems" -enable "True" -Name "Windows Server" -Comments "" -ItemType "folder" -Verbose
  161.         New-item -path "DS001:\Operating Systems" -enable "True" -Name "Windows Client" -Comments "" -ItemType "folder" -Verbose
  162.  
  163.         # Create Operating System Folders
  164.         New-item -path "DS001:\Task Sequences" -enable "True" -Name "Windows Server" -Comments "" -ItemType "folder" -Verbose
  165.         New-item -path "DS001:\Task Sequences" -enable "True" -Name "Windows Client" -Comments "" -ItemType "folder" -Verbose
  166.  
  167.         # Create Application - CleanupBeForSysprep
  168.         # Source: https://deploymentbunny.com/2014/06/05/nice-to-know-get-rid-of-all-junk-before-sysprep-and-capture-when-creating-a-reference-image-in-mdt/
  169.         # IMPORTANT REQUIRED WINDOWS UPDATES FOR WIN7 and 2008R2 : http://support.microsoft.com/kb/2852386
  170.         [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  171.         Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Action-CleanupBeforeSysprep/Action-CleanupBeforeSysprep.wsf -OutFile "$DriveLetter\ReferenceShare\AppImport\Action-CleanupBeforeSysprep.wsf"        
  172.         import-MDTApplication -path "DS001:\Applications\DeploymentBunny Scripts" -enable "True" -Name "Mikael Nystrom Action - CleanupBeforeSysprep" -ShortName "Action - CleanupBeforeSysprep" -Version "" -Publisher "Mikael Nystrom" -Language "" -CommandLine "cscript.exe Action-CleanupBeforeSysprep.wsf" -WorkingDirectory ".\Applications\Mikael Nystrom Action - CleanupBeforeSysprep" -ApplicationSourcePath "$DriveLetter\ReferenceShare\AppImport" -DestinationFolder "Mikael Nystrom Action - CleanupBeforeSysprep" -Verbose
  173.         Remove-Item "$DriveLetter\ReferenceShare\AppImport\*" -Force -Recurse
  174.  
  175.         # Create Application - Visual Studio RunTime (VC++)
  176.         # Source: https://deploymentbunny.com/2014/09/25/nice-to-havevb-script-wrapper-for-all-vc-installers-to-be-used-in-mdt/
  177.         # https://deploymentbunny.com/2014/08/05/powershell-is-king-download-all-vc-runtimes-using-a-script/
  178.         [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  179.         Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Install-X86-X64-C%2B%2B/Install-MicrosoftVisualC%2B%2Bx86x64.wsf -OutFile "$DriveLetter\ReferenceShare\AppImport\Install-MicrosoftVisualC%2B%2Bx86x64.wsf"
  180.         Move-Item "$DriveLetter\ReferenceShare\AppImport\Install-MicrosoftVisualC%2B%2Bx86x64.wsf" "$DriveLetter\ReferenceShare\AppImport\Install-MicrosoftVisualC++x86x64.wsf"
  181.         Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Get-AllC%2B%2BRuntimes/Get-Downloads.ps1 -OutFile "$DriveLetter\ReferenceShare\AppImport\Get-Downloads.ps1"
  182.         Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Get-AllC%2B%2BRuntimes/download.xml -OutFile "$DriveLetter\ReferenceShare\AppImport\download.xml"
  183.         & $DriveLetter\ReferenceShare\AppImport\Get-Downloads.ps1 -DownloadFile $DriveLetter\ReferenceShare\AppImport\download.xml -DownloadFolder $DriveLetter\ReferenceShare\AppImport\
  184.         import-MDTApplication -path "DS001:\Applications\DeploymentBunny Scripts" -enable "True" -Name "Mikael Nystrom Action - Install-MicrosoftVisualC++" -ShortName "Action - Install-MicrosoftVisualC++" -Version "" -Publisher "Mikael Nystrom" -Language "" -CommandLine "cscript.exe Install-MicrosoftVisalC++x86x64.wsf" -WorkingDirectory ".\Applications\Mikael Nystrom Action - Install-MicrosoftVisualC++" -ApplicationSourcePath "$DriveLetter\ReferenceShare\AppImport" -DestinationFolder "Mikael Nystrom Action - Install-MicrosoftVisualC++" -Verbose
  185.         Remove-Item "$DriveLetter\ReferenceShare\AppImport\*" -Force -Recurse
  186.  
  187.         # Configure Bootstrap.ini Account Details
  188.         If ((Get-WmiObject Win32_Computersystem).partofdomain -eq $True) {
  189.  
  190.             Write-Host " "
  191.             $TextMessage = Write-Host " Please Enter an Active Directory Account"
  192.             $UserName = Read-Host " Please Enter Service Account"
  193.             $UserPassword = Read-Host " Please Enter Service Account Password"
  194.  
  195.             Get-Content -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" | Out-Null
  196.             #Add-Content -Value DeployRoot=\\$env:COMPUTERNAME\CaptureShare$ -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
  197.             Add-Content -Value " " -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
  198.             Add-Content -Value SkipBDDWelcome=YES -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
  199.             Add-Content -Value UserID=$UserName -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
  200.             Add-Content -Value UserPassword="$UserPassword" -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
  201.             Add-Content -Value UserDomain=$env:UserDnsDomain -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
  202.             Write-Host " "
  203.  
  204.         }
  205.         else {
  206.  
  207.             # Generate a random password
  208.             # Source: http://blog.oddbit.com/2012/11/04/powershell-random-passwords/
  209.             Function random-password ($length = 15) {
  210.                 $punc = 46..46
  211.                 $digits = 48..57
  212.                 $letters = 65..90 + 97..122
  213.  
  214.                 # Thanks to
  215.                 # https://blogs.technet.com/b/heyscriptingguy/archive/2012/01/07/use-pow
  216.                 $password = get-random -count $length `
  217.                     -input ($punc + $digits + $letters) |
  218.                     % -begin { $aa = $null } `
  219.                     -process {$aa += [char]$_} `
  220.                     -end {$aa}
  221.  
  222.                 return $password
  223.             }
  224.  
  225.             $GeneratedPassword = random-password
  226.            
  227.             $UserName = "mdt_connect"
  228.             $UserPassword = $GeneratedPassword | ConvertTo-SecureString -AsPlainText -Force
  229.  
  230.             New-LocalUser -Name "$UserName" -FullName "mdt_connect" -Description "Local MDT Service Account Used with LiteTouch" -Password $UserPassword
  231.             Write-Host " "
  232.            
  233.             Get-Content -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" | Out-Null
  234.             Add-Content -Value DeployRoot=\\$env:COMPUTERNAME\CaptureShare$ -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
  235.             Add-Content -Value " " -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
  236.             Add-Content -Value SkipBDDWelcome=YES -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
  237.             Add-Content -Value UserID=$UserName -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
  238.             Add-Content -Value UserPassword=$GeneratedPassword -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
  239.             Add-Content -Value UserDomain=$env:UserDnsDomain -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
  240.             Write-Host " "
  241.  
  242.         }
  243.  
  244.         # Generate LiteTouch Boot Media
  245.         Write-Host ""
  246.         Write-Host "Updating LiteTouch Boot Media"
  247.         update-MDTDeploymentShare -path "DS001:" -Force -Verbose
  248.  
  249.         # Launch Microsoft Deployment Toolkit
  250.         & "C:\Program Files\Microsoft Deployment Toolkit\Bin\DeploymentWorkbench.msc"
  251.  
  252.         Write-Host ""
  253.         Write-Host "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #" -ForegroundColor Green
  254.         Write-Host "                                                           "
  255.         Write-Host "   MDT ReferenceShare is Provisioned and Ready to Use!     " -ForegroundColor Cyan
  256.         Write-Host "                                                           "
  257.         Write-Host "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #" -ForegroundColor Green
  258.  
  259.         # Script Cleanup
  260.         Remove-PSDrive DS001
  261.         If (!( $MDTSetup -eq $null )) {
  262.             Remove-Item $MDTSetup -Force
  263.         }
  264.     }
  265.     2 {
  266.         # Import Microsoft Deployment Toolkit Powershell Module
  267.         Import-Module "C:\Program Files\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"    
  268.        
  269.         # Configure Directory Letter for Folder
  270.         $DriveLetter = Read-Host "Please enter a driver letter to provision the DeploymentShare"
  271.        
  272.         # Query Drive Letter and Check if Already Created - Mainly for Development within Lab Environments.
  273.         $CheckDir = "$DriveLetter\DeploymentShare"
  274.         If (Test-Path $CheckDir) {
  275.             Write-Host ""  
  276.             Write-Host "WARNING... Directory Found under: $DriveLetter\DeploymentShare" -ForegroundColor Red
  277.    
  278.             $Query = Read-Host "Do you want to reset your DeploymentShare Directory [Y] or [N]"
  279.             If ($Query -eq 'Y') {
  280.                 If ((Get-WmiObject Win32_Computersystem).partofdomain -eq $True) {
  281.                     Remove-SMBShare -Name "DeploymentShare$" -Force
  282.                     Remove-Item -Path "$DriveLetter\DeploymentShare" -Force -Recurse
  283.            
  284.                 }
  285.                 Else {
  286.                     Remove-SMBShare -Name "DeploymentShare$" -Force
  287.                     Remove-Item -Path "$DriveLetter\DeploymentShare" -Force -Recurse
  288.                     Remove-LocalUser -Name "mdt_connect"
  289.                 }  
  290.             }
  291.         }
  292.    
  293.         # Provision Deployment Work Space
  294.         New-Item -Path "$DriveLetter\DeploymentShare" -ItemType directory
  295.         New-SmbShare -Name "DeploymentShare$" -Path "$DriveLetter\DeploymentShare" -FullAccess Administrators
  296.         New-PSDrive -Name "DS001" -PSProvider "MDTProvider" -Root "$DriveLetter\DeploymentShare" -Description "MDT Reference Share" -NetworkPath "\\$env:COMPUTERNAME\DeploymentShare$" -Verbose | add-MDTPersistentDrive -Verbose
  297.         New-Item -Path "$DriveLetter\DeploymentShare\AppImport" -ItemType directory
  298.    
  299.         # Create Applications Folders
  300.         New-item -Path "DS001:\Applications" -enable "True" -Name "DeploymentBunny Scripts" -Comments "" -ItemType "folder" -Verbos
  301.         New-item -path "DS001:\Applications" -enable "True" -Name "Microsoft Applications" -Comments "" -ItemType "folder" -Verbose
  302.    
  303.         # Create Operating System Folders
  304.         New-item -path "DS001:\Operating Systems" -enable "True" -Name "Windows Server" -Comments "" -ItemType "folder" -Verbose
  305.         New-item -path "DS001:\Operating Systems" -enable "True" -Name "Windows Client" -Comments "" -ItemType "folder" -Verbose
  306.    
  307.         # Create Operating System Folders
  308.         New-item -path "DS001:\Task Sequences" -enable "True" -Name "Windows Server" -Comments "" -ItemType "folder" -Verbose
  309.         New-item -path "DS001:\Task Sequences" -enable "True" -Name "Windows Client" -Comments "" -ItemType "folder" -Verbose
  310.    
  311.         # Create Application - CleanupBeForSysprep
  312.         # Source: https://deploymentbunny.com/2014/06/05/nice-to-know-get-rid-of-all-junk-before-sysprep-and-capture-when-creating-a-reference-image-in-mdt/
  313.         # IMPORTANT REQUIRED WINDOWS UPDATES FOR WIN7 and 2008R2 : http://support.microsoft.com/kb/2852386
  314.         [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  315.         Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Action-CleanupBeforeSysprep/Action-CleanupBeforeSysprep.wsf -OutFile "$DriveLetter\DeploymentShare\AppImport\Action-CleanupBeforeSysprep.wsf"        
  316.         import-MDTApplication -path "DS001:\Applications\DeploymentBunny Scripts" -enable "True" -Name "Mikael Nystrom Action - CleanupBeforeSysprep" -ShortName "Action - CleanupBeforeSysprep" -Version "" -Publisher "Mikael Nystrom" -Language "" -CommandLine "cscript.exe Action-CleanupBeforeSysprep.wsf" -WorkingDirectory ".\Applications\Mikael Nystrom Action - CleanupBeforeSysprep" -ApplicationSourcePath "$DriveLetter\DeploymentShare\AppImport" -DestinationFolder "Mikael Nystrom Action - CleanupBeforeSysprep" -Verbose
  317.         Remove-Item "$DriveLetter\DeploymentShare\AppImport\*" -Force -Recurse
  318.    
  319.         # Create Application - Visual Studio RunTime (VC++)
  320.         # Source: https://deploymentbunny.com/2014/09/25/nice-to-havevb-script-wrapper-for-all-vc-installers-to-be-used-in-mdt/
  321.         # https://deploymentbunny.com/2014/08/05/powershell-is-king-download-all-vc-runtimes-using-a-script/
  322.         [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  323.         Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Install-X86-X64-C%2B%2B/Install-MicrosoftVisualC%2B%2Bx86x64.wsf -OutFile "$DriveLetter\DeploymentShare\AppImport\Install-MicrosoftVisualC%2B%2Bx86x64.wsf"
  324.         Move-Item "$DriveLetter\DeploymentShare\AppImport\Install-MicrosoftVisualC%2B%2Bx86x64.wsf" "$DriveLetter\DeploymentShare\AppImport\Install-MicrosoftVisualC++x86x64.wsf"
  325.         Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Get-AllC%2B%2BRuntimes/Get-Downloads.ps1 -OutFile "$DriveLetter\DeploymentShare\AppImport\Get-Downloads.ps1"
  326.         Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Get-AllC%2B%2BRuntimes/download.xml -OutFile "$DriveLetter\DeploymentShare\AppImport\download.xml"
  327.         & $DriveLetter\DeploymentShare\AppImport\Get-Downloads.ps1 -DownloadFile $DriveLetter\DeploymentShare\AppImport\download.xml -DownloadFolder $DriveLetter\DeploymentShare\AppImport\
  328.         import-MDTApplication -path "DS001:\Applications\DeploymentBunny Scripts" -enable "True" -Name "Mikael Nystrom Action - Install-MicrosoftVisualC++" -ShortName "Action - Install-MicrosoftVisualC++" -Version "" -Publisher "Mikael Nystrom" -Language "" -CommandLine "cscript.exe Install-MicrosoftVisalC++x86x64.wsf" -WorkingDirectory ".\Applications\Mikael Nystrom Action - Install-MicrosoftVisualC++" -ApplicationSourcePath "$DriveLetter\DeploymentShare\AppImport" -DestinationFolder "Mikael Nystrom Action - Install-MicrosoftVisualC++" -Verbose
  329.         Remove-Item "$DriveLetter\DeploymentShare\AppImport\*" -Force -Recurse
  330.    
  331.         # Configure Bootstrap.ini Account Details
  332.         If ((Get-WmiObject Win32_Computersystem).partofdomain -eq $True) {
  333.    
  334.             Write-Host " "
  335.             $TextMessage = Write-Host " Please Enter an Active Directory Account"
  336.             $UserName = Read-Host " Please Enter Service Account"
  337.             $UserPassword = Read-Host " Please Enter Service Account Password"
  338.    
  339.             Get-Content -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" | Out-Null
  340.             #Add-Content -Value DeployRoot=\\$env:COMPUTERNAME\CaptureShare$ -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
  341.             Add-Content -Value " " -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
  342.             Add-Content -Value SkipBDDWelcome=YES -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
  343.             Add-Content -Value UserID=$UserName -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
  344.             Add-Content -Value UserPassword="$UserPassword" -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
  345.             Add-Content -Value UserDomain=$env:UserDnsDomain -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
  346.             Write-Host " "
  347.    
  348.         }
  349.         else {
  350.    
  351.             # Generate a random password
  352.             # Source: http://blog.oddbit.com/2012/11/04/powershell-random-passwords/
  353.             Function random-password ($length = 15) {
  354.                 $punc = 46..46
  355.                 $digits = 48..57
  356.                 $letters = 65..90 + 97..122
  357.    
  358.                 # Thanks to
  359.                 # https://blogs.technet.com/b/heyscriptingguy/archive/2012/01/07/use-pow
  360.                 $password = get-random -count $length `
  361.                     -input ($punc + $digits + $letters) |
  362.                     % -begin { $aa = $null } `
  363.                     -process {$aa += [char]$_} `
  364.                     -end {$aa}
  365.    
  366.                 return $password
  367.             }
  368.    
  369.             $GeneratedPassword = random-password
  370.            
  371.             $UserName = "mdt_connect"
  372.             $UserPassword = $GeneratedPassword | ConvertTo-SecureString -AsPlainText -Force
  373.    
  374.             New-LocalUser -Name "$UserName" -FullName "mdt_connect" -Description "Local MDT Service Account Used with LiteTouch" -Password $UserPassword
  375.             Write-Host " "
  376.            
  377.             Get-Content -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" | Out-Null
  378.             Add-Content -Value DeployRoot=\\$env:COMPUTERNAME\CaptureShare$ -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
  379.             Add-Content -Value " " -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
  380.             Add-Content -Value SkipBDDWelcome=YES -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
  381.             Add-Content -Value UserID=$UserName -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
  382.             Add-Content -Value UserPassword=$GeneratedPassword -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
  383.             Add-Content -Value UserDomain=$env:UserDnsDomain -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
  384.             Write-Host " "
  385.    
  386.         }
  387.    
  388.         # Generate LiteTouch Boot Media
  389.         Write-Host ""
  390.         Write-Host "Updating LiteTouch Boot Media"
  391.         update-MDTDeploymentShare -path "DS001:" -Force -Verbose
  392.    
  393.         # Launch Microsoft Deployment Toolkit
  394.         & "C:\Program Files\Microsoft Deployment Toolkit\Bin\DeploymentWorkbench.msc"
  395.    
  396.         Write-Host ""
  397.         Write-Host "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #" -ForegroundColor Green
  398.         Write-Host "                                                           "
  399.         Write-Host "   MDT DeploymentShare is Provisioned and Ready to Use!     " -ForegroundColor Cyan
  400.         Write-Host "                                                           "
  401.         Write-Host "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #" -ForegroundColor Green
  402.    
  403.         # Script Cleanup
  404.         Remove-PSDrive DS001
  405.         If (!( $MDTSetup -eq $null )) {
  406.             Remove-Item $MDTSetup -Force
  407.         }
  408.     }    
  409.     3 {
  410.         Clear-Host
  411.         Exit    
  412.     }  
  413. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement