brianfgonzalez

vagrant_mdt

Sep 27th, 2016
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. If (!(Test-Path $profile)) { New-itemtype file –force $profile }
  2. Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\NetSecurity\NetSecurity.psd1"
  3. Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\SmbShare\SmbShare.psd1"
  4. Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\NetTCPIP\NetTCPIP.psd1"
  5. Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\ServerManager\ServerManager.psd1"
  6.  
  7. function AddFolder {
  8. Param ([string]$xmlPath,[string]$nodeName)
  9. if (!(Test-Path($xmlPath))) {
  10. [xml]$xml = "<groups><group /></groups>"
  11. }elseif (!(([xml](type $xmlPath)).groups.HasChildNodes)) {
  12. [xml]$xml = "<groups><group /></groups>"
  13. }else{
  14. [xml]$xml = (type $xmlPath)
  15. }
  16. $newGUID = ([guid]::NewGuid())
  17. [xml]$newNode = @"
  18. <group guid="{$newGUID}" enable="True">
  19.    <Name>$nodeName</Name>
  20. </group>
  21. "@
  22. $xml.groups.AppendChild($xml.ImportNode($newNode.group, $true))
  23. $xml.save($xmlPath)
  24. }
  25.  
  26. #Get-NetIPAddress -InterfaceAlias "Ethernet" -AddressFamily IPv4 | fl -Property "IPAddress"
  27. #Test-Connection -ComputerName "google.com"
  28.  
  29. #Start-Sleep -Seconds 180 -Verbose
  30. If (!(Invoke-WebRequest -Uri "https://chocolatey.org/install.ps1" -UseBasicParsing | Invoke-Expression)) {Exit}
  31. Start-Process -FilePath "$env:SystemDrive\ProgramData\chocolatey\bin\choco.exe" -ArgumentList "feature enable -n=allowGlobalConfirmation" -NoNewWindow -Wait
  32. Start-Process -FilePath "$env:SystemDrive\ProgramData\chocolatey\bin\choco.exe" -ArgumentList "feature enable -n=allowEmptyChecksums" -NoNewWindow -Wait
  33. Start-Process -FilePath "$env:SystemDrive\ProgramData\chocolatey\bin\choco.exe" -ArgumentList "source add --name=""local"" --source=""$env:SystemDrive\vagrant_data\packages"" --priority=""1""" -NoNewWindow -Wait
  34. Start-Process -FilePath "$env:SystemDrive\ProgramData\chocolatey\bin\choco.exe" -ArgumentList "config set --cache-location=""$env:SystemDrive\vagrant_data\cache""" -NoNewWindow -Wait
  35. Start-Process -FilePath "$env:SystemDrive\ProgramData\chocolatey\bin\choco.exe" -ArgumentList "install windows-adk-winpe mdt hackfont notepadplusplus 7zip.install sccmtoolkit imagemagick pscx --limitoutput --allowunofficial" -NoNewWindow -Wait
  36. Remove-Item -Path "$env:UserProfile\Desktop\ImageMagick Display.lnk" -Force
  37. Import-Module "$env:ProgramFiles\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"
  38.  
  39. <# #Install Active Directory
  40. $SafeModeAdministratorPasswordText = "P@ssw0rd"
  41. $SafeModeAdministratorPassword = ConvertTo-SecureString -AsPlainText $SafeModeAdministratorPasswordText -Force
  42. Install-WindowsFeature AD-Domain-Services
  43. Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\ADDSDeployment\ADDSDeployment.psd1"
  44. Install-ADDSForest -CreateDnsDelegation:$false -DatabasePath "$env:SystemDrive\Windows\NTDS" -DomainMode "Win2012R2" -DomainName "pdeploy.com" `
  45.  -DomainNetbiosName "pdeploy" -ForestMode "Win2012R2" -InstallDns:$true -LogPath "$env:SystemDrive\Windows\NTDS" -NoRebootOnCompletion:$true `
  46.  -SysvolPath "$env:SystemDrive\Windows\SYSVOL" -Force:$true -SafeModeAdministratorPassword $SafeModeAdministratorPassword
  47.  
  48.  #Install DHCP and configure
  49.  Install-WindowsFeature -Name 'DHCP' -IncludeManagementTools
  50.  Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\DhcpServer\DhcpServer.psd1"
  51.  Add-DhcpServerv4Scope -Name "Bridged" -StartRange 192.168.50.100 -EndRange 192.168.50.250 -SubnetMask 255.255.255.0 -Description "Bridged Network"
  52.  
  53. # Install WDS Role and Configure Server
  54. Install-WindowsFeature WDS
  55. #cinst "Microsoft-Windows-Deployment-Services" "Microsoft-Windows-Deployment-Services-Deployment-Server" "Microsoft-Windows-Deployment-Services-Transport-Server" --source windowsfeatures
  56. Start-Process -FilePath "cmd.exe" -ArgumentList "/c wdsutil /initialize-server /server:$env:computername /reminst:$env:SystemDrive\RemoteInstall" -ErrorAction "SilentlyContinue" -NoNewWindow -Wait
  57. Start-Process -FilePath "cmd.exe" -ArgumentList "/c wdsutil /set-server /answerclients:all" -ErrorAction "SilentlyContinue" -NoNewWindow -Wait #>
  58.  
  59. New-Item -Path "C:\DeploymentShare" -ItemType directory -Verbose
  60. New-SmbShare -Name "DS" -Path "C:\DeploymentShare" -FullAccess Administrators -Verbose
  61. # Start-Process -FilePath "cmd.exe" -ArgumentList "/c net share DS=C:\DeploymentShare /GRANT:Everyone,FULL" -ErrorAction "SilentlyContinue" -NoNewWindow -Wait
  62. Start-Process -FilePath "cmd.exe" -ArgumentList "/c net user MDT P@ssw0rd /add" -ErrorAction "SilentlyContinue" -NoNewWindow -Verbose -Wait
  63. Start-Process -FilePath "cmd.exe" -ArgumentList "/c net localgroup Administrators MDT /add" -ErrorAction "SilentlyContinue" -NoNewWindow -Verbose -Wait
  64. Start-Process -FilePath "cmd.exe" -ArgumentList '/c wmic UserAccount where Name="MDT" set PasswordExpires=False' -ErrorAction "SilentlyContinue" -NoNewWindow -Verbose -Wait
  65.  
  66. $path = "${env:ProgramFiles(x86)}\Notepad++\stylers.model.xml"
  67. $xml = [xml](Get-Content $path)
  68. $node = $xml.NotepadPlus.GlobalStyles.WidgetStyle | ? { $_.name -eq "Global override" }
  69. $node.fontName = "Hack"
  70. $node.fontSize = "11"
  71. $xml.Save($path)
  72. Start-Process -FilePath "setx.exe" -ArgumentList "PATH ""$env:Path;${env:ProgramFiles(x86)}\Notepad++"" /M" -ErrorAction "SilentlyContinue" -NoNewWindow -Wait
  73. #[Environment]::SetEnvironmentVariable("Path", $env:Path + ";${env:ProgramFiles(x86)}\Notepad++", [EnvironmentVariableTarget]::Machine)
  74.  
  75. new-PSDrive -Name "DS001" -PSProvider "MDTProvider" -Root "$env:SystemDrive\DeploymentShare" -Description "DS" -NetworkPath "\\$env:computername\DS" -Verbose | add-MDTPersistentDrive -Verbose
  76. $bootstrapPath = "C:\DeploymentShare\Control\Bootstrap.ini"
  77. if (Test-Path($bootstrapPath)) { Remove-Item $bootstrapPath -Force -Verbose }
  78. Add-Content -Path $bootstrapPath -Value "[Settings]`r`nPriority=Default`r`n[Default]`r`nDeployRoot=\\$env:computername\DS" -Force -ErrorAction SilentlyContinue -Verbose
  79. Add-Content -Path $bootstrapPath -Value "`r`nSkipBDDWelcome=YES" -Force -ErrorAction SilentlyContinue -Verbose
  80. Add-Content -Path $bootstrapPath -Value "`r`nUserDomain=$env:computername`r`nUserID=MDT`r`nUserpassword=P@ssw0rd" -Force -ErrorAction SilentlyContinue -Verbose
  81.  
  82. $imagemagick = (dir "C:\Program Files\imagemagick*\magick.exe").FullName
  83. $datestamp, $architecture = (Get-Date -format "dd-MMM-yyyy HH:mm"), "x64"
  84. $fontsize, $fontfamily, $fontstyle, $fontcolor = "14", "Tahoma", "Normal", "Blue"
  85. $convertstring = 'convert "C:\Program Files\Microsoft Deployment Toolkit\Samples\Background.bmp"'+`
  86. ' -resize "1024x768" -font "'+$fontfamily+'" -style "'+$fontstyle+'" -fill "'+$fontcolor+'" -pointsize "'+$fontsize+`
  87. '" -draw "text 850,180 '''+$architecture+' @ '+$datestamp+'''" "C:\DeploymentShare\Background.bmp"'
  88. Start-Process -FilePath $imagemagick -ArgumentList $convertstring -ErrorAction "SilentlyContinue" -NoNewWindow -Wait -Verbose
  89.  
  90. $path = "$env:SystemDrive\DeploymentShare\Control\Settings.xml"
  91. $xml = [xml](Get-Content $path)
  92. $xml.Settings."SupportX86" = "False"
  93. $xml.Settings."Boot.x64.ScratchSpace" = "512"
  94. $xml.Settings."Boot.x64.BackgroundFile" = "$env:SystemDrive\DeploymentShare\Background.bmp"
  95. $xml.Settings."Boot.x64.SelectionProfile" = "Nothing"
  96. $xml.Save($path)
  97. update-MDTDeploymentShare -path "DS001:" -Verbose
  98.  
  99. $Folders = ("Win 7x86","Win 7x64","Win 10x64")
  100. ForEach ($a in $Folders ) { AddFolder -xmlPath "$env:SystemDrive\DeploymentShare\Control\ApplicationGroups.xml" -nodeName $a}
  101. ForEach ($a in $Folders ) { AddFolder -xmlPath "$env:SystemDrive\DeploymentShare\Control\DriverGroups.xml" -nodeName $a}
  102. ForEach ($a in $Folders ) { AddFolder -xmlPath "$env:SystemDrive\DeploymentShare\Control\OperatingSystemGroups.xml" -nodeName $a}
  103. $Folders = ("Win 7x86","Win 7x64","Win 10x64","Win 7x86\Deploy","Win 7x64\Deploy","Win 10x64\Deploy","Win 7x86\Capture","Win 7x64\Capture","Win 10x64\Capture","Development")
  104. ForEach ($a in $Folders ) { AddFolder -xmlPath "$env:SystemDrive\DeploymentShare\Control\TaskSequenceGroups.xml" -nodeName $a}
  105.  
  106. Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False -Verbose
  107. Copy-Item "$env:SystemDrive\DeploymentShare\Boot\LiteTouchPE_x64.iso" "$env:SystemDrive\vagrant_data\" -Force -Verbose
  108.  
  109. $SafeModeAdministratorPasswordText = "P@ssw0rd"
  110. $SafeModeAdministratorPassword = ConvertTo-SecureString -AsPlainText $SafeModeAdministratorPasswordText -Force
  111. Install-WindowsFeature AD-Domain-Services -IncludeManagementTools
  112. Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\ADDSDeployment\ADDSDeployment.psd1"
  113. Install-ADDSForest -CreateDnsDelegation:$false -DatabasePath "$env:SystemDrive\Windows\NTDS" -DomainMode "Win2012R2" -DomainName "pdeploy.com" `
  114.  -DomainNetbiosName "pdeploy" -ForestMode "Win2012R2" -InstallDns:$true -LogPath "$env:SystemDrive\Windows\NTDS" -NoRebootOnCompletion:$true `
  115.  -SysvolPath "$env:SystemDrive\Windows\SYSVOL" -Force:$true -SafeModeAdministratorPassword $SafeModeAdministratorPassword  -ErrorAction "SilentlyContinue"
  116.  
  117. Install-WindowsFeature -Name 'DHCP' -IncludeManagementTools -ErrorAction "SilentlyContinue"
  118. Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\DhcpServer\DhcpServer.psd1" -ErrorAction "SilentlyContinue"
  119. Add-DhcpServerv4Scope -Name "Bridged" -StartRange "192.168.50.100" -EndRange "192.168.50.250" -SubnetMask "255.255.255.0" -Description "Internal Network" -ErrorAction "SilentlyContinue"
  120. Install-WindowsFeature WDS -IncludeManagementTools -ErrorAction "SilentlyContinue"
  121. Start-Process -FilePath "cmd.exe" -ArgumentList '/c wdsutil /initialize-server /reminst:"$env:SystemDrive\RemoteInstall"' -ErrorAction "SilentlyContinue" -NoNewWindow -Wait
  122. Start-Process -FilePath "cmd.exe" -ArgumentList "/c wdsutil /set-server /answerclients:all" -ErrorAction "SilentlyContinue" -NoNewWindow -Wait
  123.  
  124. Restart-Computer -Force
Add Comment
Please, Sign In to add comment