Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- # Microsoft Deployment Toolkit - Automated Setup Script
- # Author: Simon Lee
- # Version Contol
- v1.0 December 2018 - Initial Script Created
- v1.1 January 2019 - Added MDT and ADK Insatll Dirctory Query to skip is software already installed.
- v1.2 ReferenceShare Inital Script Completed Added Domain Query for Service and Local Account
- v1.3 DeploymentShare Initial Script Created
- v1.3.1 Added ASCSI Slant Text and Script Title Text
- #>
- # Script Varibales
- # Microsoft Deployment Toolkit Version 6.3.8450.1000 - Pleaes update to latest version if required
- $MDTSource = "https://download.microsoft.com/download/3/3/9/339BE62D-B4B8-4956-B58D-73C4685FC492/MicrosoftDeploymentToolkit_x64.msi"
- # Windows ADK 1803 10.17134.1 - Pleaes update to latest version if required
- $ADKSource = "http://download.microsoft.com/download/6/8/9/689E62E5-C50F-407B-9C3C-B7F00F8C93C0/adk/adksetup.exe"
- # Powershell Window Title Text
- $host.ui.RawUI.WindowTitle = "Microsoft Deployment Toolkit - Automated Setup Script"
- # Clear Screen
- Clear-Host
- # Source: http://patorjk.com/software/taag/#p=display&f=Slant&t=MDT%20Automated%20Setup
- Write-Host " __ _______ ______ ___ __ __ __ _____ __ " -ForegroundColor Cyan
- Write-Host " / |/ / __ \/_ __/ / | __ __/ /_____ ____ ___ ____ _/ /____ ____/ / / ___/___ / /___ ______ " -ForegroundColor Cyan
- Write-Host " / /|_/ / / / / / / / /| |/ / / / __/ __ \/ __ `__ \/ __ `/ __/ _ \/ __ / \__ \/ _ \/ __/ / / / __ \ " -ForegroundColor Cyan
- Write-Host " / / / / /_/ / / / / ___ / /_/ / /_/ /_/ / / / / / / /_/ / /_/ __/ /_/ / ___/ / __/ /_/ /_/ / /_/ / " -ForegroundColor Cyan
- Write-Host " /_/ /_/_____/ /_/ /_/ |_\__,_/\__/\____/_/ /_/ /_/\__,_/\__/\___/\__,_/ /____/\___/\__/\__,_/ .___/ " -ForegroundColor Cyan
- Write-Host " /_/ " -ForegroundColor Cyan
- # Import Powershell Modules
- Import-Module BitsTransfer
- Import-Module SmbShare
- Write-Host ""
- Write-Host "Powershell Modules Imported" -ForegroundColor Green
- Write-Host ""
- # Query Operating System - Roles and Features
- $SystemType = (Get-WmiObject -Class Win32_ComputerSystem -Property DomainRole).DomainRole
- If ( $SystemType -eq '0' ) {
- # Client Machine - Desktop or Laptop running Windows OS
- Write-Host ""
- Write-Host "WARNING - Windows Client Machine - Can only Support Deployment Toolkit and ADK" -ForegroundColor Yellow
- Write-Host ""
- }
- If ( $SystemType -eq '1' ) {
- # Standalone Workstation
- Write-Host "Standalone Workstation - Doesnt support Roles and Features"
- }
- If ( $SystemType -eq '2' -or '3' ) {
- # Standalone Workstation
- $WDSRole = (Get-WindowsOptionalFeature -FeatureName Microsoft-Windows-Deployment-Services -Online).State
- }
- If ( $WDSRole -eq 'Disabled' ) {
- # Role Missing - Install Role
- Install-WindowsFeature -Name WDS -IncludeManagementTools
- }
- $MDTDirectory = 'C:\Program Files\Microsoft Deployment Toolkit'
- $ADKDirectory = 'C:\Program Files (x86)\Windows Kits'
- If ( Test-Path $MDTDirectory) {
- Write-Host 'Microsoft Deployment Toolkit Detected... Skipping Install' -ForegroundColor Cyan
- }
- Else {
- # Create MDT Setup Directory
- Write-Host ""
- Write-Host "For Example: C:\MDTSetup"
- $MDTSetup = Read-Host "Please specific setup directory for install media"
- New-Item -ItemType Directory -Path $MDTSetup | Out-Null
- # Microsoft Deployment Toolkit 64x - Latest Version
- Start-BitsTransfer -DisplayName 'Microsoft Deployment Toolkit Downloading' -Description ' ' -Source $MDTSource -Destination $MDTSetup\MicrosoftDeploymentToolkit_x64.msi
- Write-Host ""
- Write-Host "MDT Download Completed"
- # Installing Micosoft Deployment Toolkit
- Write-Host ""
- Write-Host "Installing MDT...."
- Start-Process -FilePath "$MDTSetup\MicrosoftDeploymentToolkit_x64.msi" -ArgumentList '/passive' -Wait
- Write-Host ""
- Write-Host "MDT Installation Completed" -ForegroundColor Green
- }
- If ( Test-Path $ADKDirectory) {
- Write-HOst 'Windows Assessment and Deployment Kit Detected... Skipping Install' -ForegroundColor Cyan
- }
- Else {
- # Windows Assessment and Deployment Kit
- Start-BitsTransfer -DisplayName 'Microsoft ADK 1803 Downloading' -Description ' ' -Source $ADKSource -Destination $MDTSetup\adksetup.exe
- Write-Host ""
- Write-Host "Windows ADK Download Completed"
- # Installing Windows Assessment and Deployment Kit - Silent Setup Reference: https://docs.microsoft.com/en-us/windows-hardware/get-started/adk-offline-install
- Write-Host ""
- Write-Host "Installing Windows ADK...."
- Start-Process -FilePath "$MDTSetup\adksetup.exe"-ArgumentList '/norestart /q /ceip off /features OptionId.WindowsPreinstallationEnvironment OptionId.DeploymentTools OptionId.UserStateMigrationTool' -Wait
- Write-Host ""
- Write-Host "ADK Installation Completed" -ForegroundColor Green
- }
- # Deployment Share Provisoning Menu
- [int]$MDTSetupMenu = 0
- while ( $MDTSetupMenu -lt 1 -or $MDTSetupMenu -gt 4) {
- Write-Host ""
- Write-Host "[1] MDT Reference Share"
- Write-Host "[2] MDT Deployment Share"
- Write-Host "[3] Quit MDT Setup Menu"
- Write-Host ""
- [Int]$MDTSetupMenu = read-Host "Please select an option."
- }
- Switch ( $MDTSetupMenu ) {
- 1 {
- # Import Microsoft Deployment Toolkit Powershell Module
- Import-Module "C:\Program Files\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"
- # Configure Directory Letter for Folder
- $DriveLetter = Read-Host "Please enter a driver letter to provision the ReferenceShare"
- # Query Drive Letter and Check if Already Created - Mainly for Development within Lab Environments.
- $CheckDir = "$DriveLetter\ReferenceShare"
- If (Test-Path $CheckDir) {
- Write-Host ""
- Write-Host "WARNING... Directory Found under: $DriveLetter\ReferenceShare" -ForegroundColor Red
- $Query = Read-Host "Do you want to reset your ReferenceShare Directory [Y] or [N]"
- If ($Query -eq 'Y') {
- If ((Get-WmiObject Win32_Computersystem).partofdomain -eq $True) {
- Remove-SMBShare -Name "ReferenceShare$" -Force
- Remove-Item -Path "$DriveLetter\ReferenceShare" -Force -Recurse
- }
- Else {
- Remove-SMBShare -Name "ReferenceShare$" -Force
- Remove-Item -Path "$DriveLetter\ReferenceShare" -Force -Recurse
- Remove-LocalUser -Name "mdt_connect"
- }
- }
- }
- # Provision Deployment Work Space
- New-Item -Path "$DriveLetter\ReferenceShare" -ItemType directory
- New-SmbShare -Name "ReferenceShare$" -Path "$DriveLetter\ReferenceShare" -FullAccess Administrators
- New-PSDrive -Name "DS001" -PSProvider "MDTProvider" -Root "$DriveLetter\ReferenceShare" -Description "MDT Reference Share" -NetworkPath "\\$env:COMPUTERNAME\ReferenceShare$" -Verbose | add-MDTPersistentDrive -Verbose
- New-Item -Path "$DriveLetter\ReferenceShare\AppImport" -ItemType directory
- # Create Applications Folders
- New-item -Path "DS001:\Applications" -enable "True" -Name "DeploymentBunny Scripts" -Comments "" -ItemType "folder" -Verbos
- New-item -path "DS001:\Applications" -enable "True" -Name "Microsoft Applications" -Comments "" -ItemType "folder" -Verbose
- # Create Operating System Folders
- New-item -path "DS001:\Operating Systems" -enable "True" -Name "Windows Server" -Comments "" -ItemType "folder" -Verbose
- New-item -path "DS001:\Operating Systems" -enable "True" -Name "Windows Client" -Comments "" -ItemType "folder" -Verbose
- # Create Operating System Folders
- New-item -path "DS001:\Task Sequences" -enable "True" -Name "Windows Server" -Comments "" -ItemType "folder" -Verbose
- New-item -path "DS001:\Task Sequences" -enable "True" -Name "Windows Client" -Comments "" -ItemType "folder" -Verbose
- # Create Application - CleanupBeForSysprep
- # 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/
- # IMPORTANT REQUIRED WINDOWS UPDATES FOR WIN7 and 2008R2 : http://support.microsoft.com/kb/2852386
- [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
- Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Action-CleanupBeforeSysprep/Action-CleanupBeforeSysprep.wsf -OutFile "$DriveLetter\ReferenceShare\AppImport\Action-CleanupBeforeSysprep.wsf"
- 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
- Remove-Item "$DriveLetter\ReferenceShare\AppImport\*" -Force -Recurse
- # Create Application - Visual Studio RunTime (VC++)
- # Source: https://deploymentbunny.com/2014/09/25/nice-to-havevb-script-wrapper-for-all-vc-installers-to-be-used-in-mdt/
- # https://deploymentbunny.com/2014/08/05/powershell-is-king-download-all-vc-runtimes-using-a-script/
- [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
- 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"
- Move-Item "$DriveLetter\ReferenceShare\AppImport\Install-MicrosoftVisualC%2B%2Bx86x64.wsf" "$DriveLetter\ReferenceShare\AppImport\Install-MicrosoftVisualC++x86x64.wsf"
- 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"
- Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Get-AllC%2B%2BRuntimes/download.xml -OutFile "$DriveLetter\ReferenceShare\AppImport\download.xml"
- & $DriveLetter\ReferenceShare\AppImport\Get-Downloads.ps1 -DownloadFile $DriveLetter\ReferenceShare\AppImport\download.xml -DownloadFolder $DriveLetter\ReferenceShare\AppImport\
- 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
- Remove-Item "$DriveLetter\ReferenceShare\AppImport\*" -Force -Recurse
- # Configure Bootstrap.ini Account Details
- If ((Get-WmiObject Win32_Computersystem).partofdomain -eq $True) {
- Write-Host " "
- $TextMessage = Write-Host " Please Enter an Active Directory Account"
- $UserName = Read-Host " Please Enter Service Account"
- $UserPassword = Read-Host " Please Enter Service Account Password"
- Get-Content -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" | Out-Null
- #Add-Content -Value DeployRoot=\\$env:COMPUTERNAME\CaptureShare$ -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
- Add-Content -Value " " -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
- Add-Content -Value SkipBDDWelcome=YES -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
- Add-Content -Value UserID=$UserName -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
- Add-Content -Value UserPassword="$UserPassword" -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
- Add-Content -Value UserDomain=$env:UserDnsDomain -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
- Write-Host " "
- }
- else {
- # Generate a random password
- # Source: http://blog.oddbit.com/2012/11/04/powershell-random-passwords/
- Function random-password ($length = 15) {
- $punc = 46..46
- $digits = 48..57
- $letters = 65..90 + 97..122
- # Thanks to
- # https://blogs.technet.com/b/heyscriptingguy/archive/2012/01/07/use-pow
- $password = get-random -count $length `
- -input ($punc + $digits + $letters) |
- % -begin { $aa = $null } `
- -process {$aa += [char]$_} `
- -end {$aa}
- return $password
- }
- $GeneratedPassword = random-password
- $UserName = "mdt_connect"
- $UserPassword = $GeneratedPassword | ConvertTo-SecureString -AsPlainText -Force
- New-LocalUser -Name "$UserName" -FullName "mdt_connect" -Description "Local MDT Service Account Used with LiteTouch" -Password $UserPassword
- Write-Host " "
- Get-Content -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" | Out-Null
- Add-Content -Value DeployRoot=\\$env:COMPUTERNAME\CaptureShare$ -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
- Add-Content -Value " " -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
- Add-Content -Value SkipBDDWelcome=YES -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
- Add-Content -Value UserID=$UserName -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
- Add-Content -Value UserPassword=$GeneratedPassword -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
- Add-Content -Value UserDomain=$env:UserDnsDomain -Path "$DriveLetter\ReferenceShare\Control\Bootstrap.ini" -Force
- Write-Host " "
- }
- # Generate LiteTouch Boot Media
- Write-Host ""
- Write-Host "Updating LiteTouch Boot Media"
- update-MDTDeploymentShare -path "DS001:" -Force -Verbose
- # Launch Microsoft Deployment Toolkit
- & "C:\Program Files\Microsoft Deployment Toolkit\Bin\DeploymentWorkbench.msc"
- Write-Host ""
- Write-Host "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #" -ForegroundColor Green
- Write-Host " "
- Write-Host " MDT ReferenceShare is Provisioned and Ready to Use! " -ForegroundColor Cyan
- Write-Host " "
- Write-Host "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #" -ForegroundColor Green
- # Script Cleanup
- Remove-PSDrive DS001
- If (!( $MDTSetup -eq $null )) {
- Remove-Item $MDTSetup -Force
- }
- }
- 2 {
- # Import Microsoft Deployment Toolkit Powershell Module
- Import-Module "C:\Program Files\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"
- # Configure Directory Letter for Folder
- $DriveLetter = Read-Host "Please enter a driver letter to provision the DeploymentShare"
- # Query Drive Letter and Check if Already Created - Mainly for Development within Lab Environments.
- $CheckDir = "$DriveLetter\DeploymentShare"
- If (Test-Path $CheckDir) {
- Write-Host ""
- Write-Host "WARNING... Directory Found under: $DriveLetter\DeploymentShare" -ForegroundColor Red
- $Query = Read-Host "Do you want to reset your DeploymentShare Directory [Y] or [N]"
- If ($Query -eq 'Y') {
- If ((Get-WmiObject Win32_Computersystem).partofdomain -eq $True) {
- Remove-SMBShare -Name "DeploymentShare$" -Force
- Remove-Item -Path "$DriveLetter\DeploymentShare" -Force -Recurse
- }
- Else {
- Remove-SMBShare -Name "DeploymentShare$" -Force
- Remove-Item -Path "$DriveLetter\DeploymentShare" -Force -Recurse
- Remove-LocalUser -Name "mdt_connect"
- }
- }
- }
- # Provision Deployment Work Space
- New-Item -Path "$DriveLetter\DeploymentShare" -ItemType directory
- New-SmbShare -Name "DeploymentShare$" -Path "$DriveLetter\DeploymentShare" -FullAccess Administrators
- New-PSDrive -Name "DS001" -PSProvider "MDTProvider" -Root "$DriveLetter\DeploymentShare" -Description "MDT Reference Share" -NetworkPath "\\$env:COMPUTERNAME\DeploymentShare$" -Verbose | add-MDTPersistentDrive -Verbose
- New-Item -Path "$DriveLetter\DeploymentShare\AppImport" -ItemType directory
- # Create Applications Folders
- New-item -Path "DS001:\Applications" -enable "True" -Name "DeploymentBunny Scripts" -Comments "" -ItemType "folder" -Verbos
- New-item -path "DS001:\Applications" -enable "True" -Name "Microsoft Applications" -Comments "" -ItemType "folder" -Verbose
- # Create Operating System Folders
- New-item -path "DS001:\Operating Systems" -enable "True" -Name "Windows Server" -Comments "" -ItemType "folder" -Verbose
- New-item -path "DS001:\Operating Systems" -enable "True" -Name "Windows Client" -Comments "" -ItemType "folder" -Verbose
- # Create Operating System Folders
- New-item -path "DS001:\Task Sequences" -enable "True" -Name "Windows Server" -Comments "" -ItemType "folder" -Verbose
- New-item -path "DS001:\Task Sequences" -enable "True" -Name "Windows Client" -Comments "" -ItemType "folder" -Verbose
- # Create Application - CleanupBeForSysprep
- # 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/
- # IMPORTANT REQUIRED WINDOWS UPDATES FOR WIN7 and 2008R2 : http://support.microsoft.com/kb/2852386
- [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
- Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Action-CleanupBeforeSysprep/Action-CleanupBeforeSysprep.wsf -OutFile "$DriveLetter\DeploymentShare\AppImport\Action-CleanupBeforeSysprep.wsf"
- 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
- Remove-Item "$DriveLetter\DeploymentShare\AppImport\*" -Force -Recurse
- # Create Application - Visual Studio RunTime (VC++)
- # Source: https://deploymentbunny.com/2014/09/25/nice-to-havevb-script-wrapper-for-all-vc-installers-to-be-used-in-mdt/
- # https://deploymentbunny.com/2014/08/05/powershell-is-king-download-all-vc-runtimes-using-a-script/
- [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
- 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"
- Move-Item "$DriveLetter\DeploymentShare\AppImport\Install-MicrosoftVisualC%2B%2Bx86x64.wsf" "$DriveLetter\DeploymentShare\AppImport\Install-MicrosoftVisualC++x86x64.wsf"
- 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"
- Invoke-WebRequest -Uri https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Get-AllC%2B%2BRuntimes/download.xml -OutFile "$DriveLetter\DeploymentShare\AppImport\download.xml"
- & $DriveLetter\DeploymentShare\AppImport\Get-Downloads.ps1 -DownloadFile $DriveLetter\DeploymentShare\AppImport\download.xml -DownloadFolder $DriveLetter\DeploymentShare\AppImport\
- 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
- Remove-Item "$DriveLetter\DeploymentShare\AppImport\*" -Force -Recurse
- # Configure Bootstrap.ini Account Details
- If ((Get-WmiObject Win32_Computersystem).partofdomain -eq $True) {
- Write-Host " "
- $TextMessage = Write-Host " Please Enter an Active Directory Account"
- $UserName = Read-Host " Please Enter Service Account"
- $UserPassword = Read-Host " Please Enter Service Account Password"
- Get-Content -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" | Out-Null
- #Add-Content -Value DeployRoot=\\$env:COMPUTERNAME\CaptureShare$ -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
- Add-Content -Value " " -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
- Add-Content -Value SkipBDDWelcome=YES -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
- Add-Content -Value UserID=$UserName -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
- Add-Content -Value UserPassword="$UserPassword" -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
- Add-Content -Value UserDomain=$env:UserDnsDomain -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
- Write-Host " "
- }
- else {
- # Generate a random password
- # Source: http://blog.oddbit.com/2012/11/04/powershell-random-passwords/
- Function random-password ($length = 15) {
- $punc = 46..46
- $digits = 48..57
- $letters = 65..90 + 97..122
- # Thanks to
- # https://blogs.technet.com/b/heyscriptingguy/archive/2012/01/07/use-pow
- $password = get-random -count $length `
- -input ($punc + $digits + $letters) |
- % -begin { $aa = $null } `
- -process {$aa += [char]$_} `
- -end {$aa}
- return $password
- }
- $GeneratedPassword = random-password
- $UserName = "mdt_connect"
- $UserPassword = $GeneratedPassword | ConvertTo-SecureString -AsPlainText -Force
- New-LocalUser -Name "$UserName" -FullName "mdt_connect" -Description "Local MDT Service Account Used with LiteTouch" -Password $UserPassword
- Write-Host " "
- Get-Content -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" | Out-Null
- Add-Content -Value DeployRoot=\\$env:COMPUTERNAME\CaptureShare$ -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
- Add-Content -Value " " -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
- Add-Content -Value SkipBDDWelcome=YES -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
- Add-Content -Value UserID=$UserName -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
- Add-Content -Value UserPassword=$GeneratedPassword -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
- Add-Content -Value UserDomain=$env:UserDnsDomain -Path "$DriveLetter\DeploymentShare\Control\Bootstrap.ini" -Force
- Write-Host " "
- }
- # Generate LiteTouch Boot Media
- Write-Host ""
- Write-Host "Updating LiteTouch Boot Media"
- update-MDTDeploymentShare -path "DS001:" -Force -Verbose
- # Launch Microsoft Deployment Toolkit
- & "C:\Program Files\Microsoft Deployment Toolkit\Bin\DeploymentWorkbench.msc"
- Write-Host ""
- Write-Host "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #" -ForegroundColor Green
- Write-Host " "
- Write-Host " MDT DeploymentShare is Provisioned and Ready to Use! " -ForegroundColor Cyan
- Write-Host " "
- Write-Host "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #" -ForegroundColor Green
- # Script Cleanup
- Remove-PSDrive DS001
- If (!( $MDTSetup -eq $null )) {
- Remove-Item $MDTSetup -Force
- }
- }
- 3 {
- Clear-Host
- Exit
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement