Public/New-OSBuild.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 |
<#
.SYNOPSIS Creates a new OSBuild from an OSBuild Task .DESCRIPTION Creates a new OSBuild from an OSBuild Task created with New-OSBuildTask .LINK https://osdbuilder.osdeploy.com/module/functions/new-osbuild .NOTES 19.10.28 MMSJazz Ready 19.10.14 Added HideCleanupProgress 19.10.13 Added SelectUpdates SkipUpdates #> function New-OSBuild { [CmdletBinding(DefaultParameterSetName='Basic')] Param ( #Specify the Name of the OSMedia to use with New-OSBuild [Parameter(ParameterSetName='Taskless', ValueFromPipelineByPropertyName=$True)] [string[]]$Name, #Name of the Task to execute [Parameter(ParameterSetName='Basic')] [string]$ByTaskName = $global:SetOSDBuilder.NewOSBuildByTaskName, #Creates an ISO of the Updated Media #oscdimg.exe from Windows ADK is required [Alias('ISO','OSDISO')] [switch]$CreateISO = $global:SetOSDBuilder.NewOSBuildCreateISO, #Use the OSMedia specified in the Task [switch]$DontUseNewestMedia = $global:SetOSDBuilder.NewOSBuildDontUseNewestMedia, #Automatically download the required updates if they are not present in the Content\OSDUpdate directory [Alias('GetDown')] [switch]$Download = $global:SetOSDBuilder.NewOSBuildDownload, #Excludes the specified Update Group #Separate multiple items with a comma -Exclude LCU,SSU #Enclose Groups with spaces with a single quote -Exclude 'ComponentDU Critical',LCU [ValidateSet(` 'AdobeSU',` 'ComponentDU',` 'ComponentDU Critical',` 'ComponentDU SafeOS',` 'DotNet',` 'DotNetCU',` 'LCU', 'SetupDU',` 'SSU' )] [string[]]$Exclude = $global:SetOSDBuilder.NewOSBuildExclude, #Excludeds specific KBs based on the KB number. # -ExcludeKB '4577010','4577015' [string[]]$ExcludeKB, #Executes Update-OSMedia #Without this parameter, Update-OSMedia is in Sandbox Mode where changes will not be made [Alias('Force')] [switch]$Execute = $global:SetOSDBuilder.NewOSBuildExecute, #Enables NetFX without creating a Task [Parameter(ParameterSetName='Taskless')] [switch]$EnableNetFX = $global:SetOSDBuilder.NewOSBuildEnableNetFX, #Hides the Dism Cleanup-Image Progress [switch]$HideCleanupProgress = $global:SetOSDBuilder.NewOSBuildHideCleanupProgress, #Includes the specified Update Group and excludes everything else #Separate multiple items with a comma -Include LCU,SSU #Enclose Groups with spaces with a single quote -Include 'ComponentDU Critical',LCU [ValidateSet(` 'AdobeSU',` 'ComponentDU',` 'ComponentDU Critical',` 'ComponentDU SafeOS',` 'DotNet',` 'DotNetCU',` 'LCU', 'SetupDU',` 'SSU' )] [string[]]$Include = $global:SetOSDBuilder.NewOSBuildInclude, #Includes only specific KBs based on the KB number. # -IncludeKB '4577010','4577015' [string[]]$IncludeKB, #Pauses the function the Install.wim is dismounted #Useful for Testing [Alias('PauseOS','PauseDismount')] [switch]$PauseDismountOS = $global:SetOSDBuilder.NewOSBuildPauseDismountOS, #Pauses the function before WinPE is dismounted #Useful for Testing [Alias('PausePE')] [switch]$PauseDismountPE = $global:SetOSDBuilder.NewOSBuildPauseDismountPE, #Add a ContentPack to Taskless OSBuild [Parameter(ParameterSetName='Taskless')] [switch]$SelectContentPacks = $global:SetOSDBuilder.NewOSBuildSelectContentPacks, #Allows you to select Updates to apply in GridView #Useful for Testing [switch]$SelectUpdates = $global:SetOSDBuilder.NewOSBuildSelectUpdates, #By default only the OSMedia that needs to be updated is displayed #This parameter includes the hidden OSMedia [Parameter(ParameterSetName='Taskless')] [Alias('ShowAllOSMedia','Superseded')] [switch]$ShowHiddenOSMedia = $global:SetOSDBuilder.NewOSBuildShowHiddenOSMedia, #Skips DISM /Cleanup-Image /StartComponentCleanup /ResetBase #Images created for Citrix PVS require this parameter #Useful for testing to reduce the time [Alias('SkipCleanup','Citrix','PVS')] [switch]$SkipComponentCleanup = $global:SetOSDBuilder.NewOSBuildSkipComponentCleanup, #Create a new OSBuild without applying ContentPacks [switch]$SkipContentPacks = $global:SetOSDBuilder.NewOSBuildSkipContentPacks, #Create a new OSBuild without applying Templates [switch]$SkipTemplates = $global:SetOSDBuilder.NewOSBuildSkipTemplates, #Allows you to skip all Updates from being applied #Useful for Testing [switch]$SkipUpdates = $global:SetOSDBuilder.NewOSBuildSkipUpdates, #Skip applying updates in WinPE #Useful for Testing [switch]$SkipUpdatesPE = $global:SetOSDBuilder.NewOSBuildSkipUpdatesPE, #Create a new OSBuild from OSMedia without a Task [Parameter(ParameterSetName='Taskless', Mandatory=$True)] [switch]$SkipTask = $global:SetOSDBuilder.NewOSBuildSkipTask ) Begin { #=================================================================================================== # Get-OSDBuilder #=================================================================================================== Get-OSDBuilder -CreatePaths -HideDetails #=================================================================================================== # Get-OSDUpdates #=================================================================================================== $AllOSDUpdates = @() $AllOSDUpdates = Get-OSDUpdates #=================================================================================================== # Get-OSDGather -Property IsAdmin #=================================================================================================== if ((Get-OSDGather -Property IsAdmin) -eq $false) { Write-Warning 'OSDBuilder: This function needs to be run as Administrator' Pause Break } } Process { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host -ForegroundColor Green "$($MyInvocation.MyCommand.Name) PROCESS" Write-Verbose "MyInvocation.MyCommand.Name: $($MyInvocation.MyCommand.Name)" Write-Verbose "PSCmdlet.ParameterSetName: $($PSCmdlet.ParameterSetName)" #=================================================================================================== # OSBuild #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { if ($PSCmdlet.ParameterSetName -eq 'Taskless') { if ($Name) { Write-Verbose "Parameter Name: $Name" $BirdBox = foreach ($Task in $Name) { $ObjectProperties = @{ Name = $Task } New-Object -TypeName PSObject -Property $ObjectProperties } } else { $BirdBox = @() if ($ShowHiddenOSMedia.IsPresent) { $BirdBox = Get-OSMedia } else { $BirdBox = Get-OSMedia -Revision OK -OSMajorVersion 10 } $BirdBox = $BirdBox | Out-GridView -PassThru -Title "Select one or more OSMedia to Build (Cancel to Exit) and press OK" } if ($null -eq $BirdBox) { Write-Warning "Could not find a matching OSMedia . . . Exiting!" Return } } else { if ($ByTaskName) { $BirdBox = @() $BirdBox = Get-OSBuildTask | Where-Object {$_.TaskName -eq "$ByTaskName"} } else { $BirdBox = @() $BirdBox = Get-OSBuildTask | Out-GridView -PassThru -Title "OSBuild Tasks: Select one or more Tasks to execute and press OK (Cancel to Exit)" } if ($null -eq $BirdBox) { Write-Warning "OSBuild Task was not selected or found . . . Exiting!" Return } } } #=================================================================================================== # Update-OSMedia #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia') { if ($Name) { $BirdBox = foreach ($Item in $Name) { Write-Verbose '========== Checking $Item' $ObjectProperties = @{ Name = $Item } New-Object -TypeName PSObject -Property $ObjectProperties } } else { $BirdBox = @() if ($ShowHiddenOSMedia.IsPresent) { $BirdBox = Get-OSMedia } else { $BirdBox = Get-OSMedia -Revision OK -Updates Update } if ($UpdateNeeded.IsPresent) { if ($BirdBox | Where-Object {$_.MajorVersion -eq 6}) { Write-Warning "UpdateNeeded does not support Legacy Operating Systems" Write-Warning "Legacy Operating Systems have been removed from the results" $BirdBox = $BirdBox | Where-Object {$_.MajorVersion -eq 10} } $BirdBox = $BirdBox | Where-Object {($_.Servicing -eq '') -or ($_.Cumulative -eq '') -or ($_.Adobe -eq '')} } $BirdBox = $BirdBox | Where-Object {($_.MajorVersion -eq 10) -or ($_.InstallationType -like "*Client*" -and $_.Version -like "6.1.7601*") -or ($_.InstallationType -like "*Server*" -and $_.Version -like "6.3*")} $BirdBox = $BirdBox | Out-GridView -PassThru -Title "Select one or more OSMedia to Update (Cancel to Exit) and press OK" } } foreach ($Bird in $BirdBox) { #=================================================================================================== # New-OSBuild #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { if ($PSCmdlet.ParameterSetName -eq 'Taskless') { #$Task = Get-OSMedia -Revision OK | Where-Object {$_.Name -eq $Bird.Name} $Task = Get-OSMedia | Where-Object {$_.Name -eq $Bird.Name} | Sort-Object ModifiedTime | Select-Object -Last 1 $TaskType = 'OSBuild' $TaskName = 'Taskless' } else { (Get-Content "$($Bird.FullName)").replace('WinPEAddDaRT', 'WinPEDaRT') | Set-Content "$($Bird.FullName)" $Task = Get-Content "$($Bird.FullName)" | ConvertFrom-Json $TaskType = $Task.TaskType $TaskName = $Task.TaskName } $TaskVersion = $Task.TaskVersion $CustomName = $Task.CustomName if ((Get-IsContentPacksEnabled) -and (!($SkipContentPacks.IsPresent))) { if ($null -eq $Task.ContentPacks) { $ContentPacks = @('_Global') } else { $ContentPacks = @('_Global') $ContentPacks = ($ContentPacks += $Task.ContentPacks) } } $TaskOSMFamily = $Task.OSMFamily $TaskOSMGuid = $Task.OSMGuid $OSMediaName = $Task.Name if (Test-Path "$SetOSDBuilderPathOSMedia\$OSMediaName") {$OSMediaPath = "$SetOSDBuilderPathOSMedia\$OSMediaName"} if (Test-Path "$SetOSDBuilderPathOSImport\$OSMediaName") {$OSMediaPath = "$SetOSDBuilderPathOSImport\$OSMediaName"} $EnableNetFX3 = $Task.EnableNetFX3 $StartLayoutXML = $Task.StartLayoutXML $UnattendXML = $Task.UnattendXML $WinPEAutoExtraFiles = $Task.WinPEAutoExtraFiles $WinPEDaRT = $Task.WinPEDart $ExtraFiles = $Task.ExtraFiles $Scripts = $Task.Scripts $Drivers = $Task.Drivers $Packages = $Task.AddWindowsPackage $RemovePackage = $Task.RemoveWindowsPackage $FeaturesOnDemand = $Task.AddFeatureOnDemand $EnableFeature = $Task.EnableWindowsOptionalFeature $DisableFeature = $Task.DisableWindowsOptionalFeature $RemoveAppx = $Task.RemoveAppxProvisionedPackage $RemoveCapability = $Task.RemoveWindowsCapability $WinPEDrivers = $Task.WinPEDrivers $WinPEScriptsPE = $Task.WinPEScriptsPE $WinPEScriptsRE = $Task.WinPEScriptsRE $WinPEScriptsSE = $Task.WinPEScriptsSE $WinPEExtraFilesPE = $Task.WinPEExtraFilesPE $WinPEExtraFilesRE = $Task.WinPEExtraFilesRE $WinPEExtraFilesSE = $Task.WinPEExtraFilesSE $WinPEADKPE = $Task.WinPEADKPE $WinPEADKRE = $Task.WinPEADKRE $WinPEADKSE = $Task.WinPEADKSE $SetAllIntl = $Task.LangSetAllIntl $SetInputLocale = $Task.LangSetInputLocale $SetSKUIntlDefaults = $Task.LangSetSKUIntlDefaults $SetSetupUILang = $Task.LangSetSetupUILang $SetSysLocale = $Task.LangSetSysLocale $SetUILang = $Task.LangSetUILang $SetUILangFallback = $Task.LangSetUILangFallback $SetUserLocale = $Task.LangSetUserLocale $LanguageFeatures = $Task.LanguageFeature $LanguagePacks = $Task.LanguagePack $LanguageInterfacePacks = $Task.LanguageInterfacePack $LocalExperiencePacks = $Task.LocalExperiencePacks $LanguageCopySources = $Task.LanguageCopySources if (!($TaskName -eq 'Taskless')) {Show-TaskInfo} } #=================================================================================================== # OSBuild Write-Verbose '19.1.1 Validate Proper TaskVersion' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and (!($TaskName -eq 'Taskless'))) { if ([System.Version]$TaskVersion -lt [System.Version]"19.1.4.0") { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "OSDBuilder Tasks need to be version 19.1.4.0 or newer" Write-Warning "Recreate this Task using New-OSBuildTask or Repair-OSBuildTask" Return } } #=================================================================================================== # OSBuild Write-Verbose '19.3.21 Select Latest OSMedia' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and (!($DontUseNewestMedia))) { if ($TaskName -eq 'Taskless') { $TaskOSMedia = Get-OSMedia | Where-Object {$_.Name -eq $OSMediaName} Write-Verbose "$TaskOSMedia | ft" } else { $TaskOSMedia = Get-OSMedia | Where-Object {$_.OSMGuid -eq $TaskOSMGuid} } $OSMediaName = $TaskOSMedia.Name $OSMediaPath = $TaskOSMedia.FullName if ($TaskOSMedia) { $OSMediaName = $TaskOSMedia.Name $OSMediaPath = $TaskOSMedia.FullName #Write-Host '========================================================================================' -ForegroundColor DarkGray #Write-Host "Task Source OSMedia" -ForegroundColor Green #Write-Host "-OSMedia Name: $OSMediaName" #Write-Host "-OSMedia Path: $OSMediaPath" #Write-Host "-OSMedia Family: $TaskOSMFamily" #Write-Host "-OSMedia Guid: $TaskOSMGuid" } $LatestOSMedia = Get-OSMedia -Revision OK | Where-Object {$_.OSMFamily -eq $TaskOSMFamily} if ($LatestOSMedia) { $OSMediaName = $LatestOSMedia.Name $OSMediaPath = $LatestOSMedia.FullName Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Latest Source OSMedia" -ForegroundColor Green Write-Host "-OSMedia Name: $OSMediaName" Write-Host "-OSMedia Path: $OSMediaPath" Write-Host "-OSMedia Family: $($LatestOSMedia.OSMFamily)" Write-Host "-OSMedia Guid: $($LatestOSMedia.OSMGuid)" } else { Write-Warning "Unable to find a matching OSMFamily $TaskOSMFamily" Return } <# if ($null -eq $OSMediaPath) { Write-Warning "Unable to find a matching OSMedia" Return } #> } #=================================================================================================== # OSBuild Write-Verbose '19.1.22 Templates' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and (Test-Path $SetOSDBuilderPathTemplates) -and (!($SkipTemplates.IsPresent))) { Get-ChildItem -Path $SetOSDBuilderPathTemplates *.json | foreach {(Get-Content "$($_.FullName)").replace('WinPEAddDaRT', 'WinPEDaRT') | Set-Content "$($_.FullName)"} $Templates = @() $Templates = Get-ChildItem -Path $SetOSDBuilderPathTemplates OSBuild*.json | ForEach-Object {Get-Content -Path $_.FullName | ConvertFrom-Json | Select-Object -Property *} if ($Templates){ Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "OSBuild Templates" -ForegroundColor Green } foreach ($Task in $Templates) { if ($Task.TaskName -like "*Global*") { Write-Host "Global: $($Task.TaskName)" } elseif ($Task.OSMFamily -eq $TaskOSMFamily) { Write-Host "OSMedia Family: $($Task.TaskName)" } else { Write-Host "Skipping: $($Task.TaskName)" -ForegroundColor DarkGray Continue } $ContentPacks += @($Task.ContentPacks | Where-Object {$_}) if (!($Task.EnableNetFX3 -eq $False)) {$EnableNetFX3 = $Task.EnableNetFX3} if ($Task.StartLayoutXML) {$StartLayoutXML = $Task.StartLayoutXML} if ($Task.UnattendXML) {$UnattendXML = $Task.UnattendXML} if (!($Task.WinPEAutoExtraFiles -eq $False)) {$WinPEAutoExtraFiles = $Task.WinPEAutoExtraFiles} if ($Task.WinPEDaRT) {$WinPEDaRT = $Task.WinPEDaRT} $ExtraFiles += @($Task.ExtraFiles | Where-Object {$_}) $Scripts += @($Task.Scripts | Where-Object {$_}) $Drivers += @($Task.Drivers | Where-Object {$_}) $Packages += @($Task.AddWindowsPackage | Where-Object {$_}) $RemovePackage += @($Task.RemoveWindowsPackage | Where-Object {$_}) $FeaturesOnDemand += @($Task.AddFeatureOnDemand | Where-Object {$_}) $EnableFeature += @($Task.EnableWindowsOptionalFeature | Where-Object {$_}) $DisableFeature += @($Task.DisableWindowsOptionalFeature | Where-Object {$_}) $RemoveAppx += @($Task.RemoveAppxProvisionedPackage | Where-Object {$_}) $RemoveCapability += @($Task.RemoveWindowsCapability | Where-Object {$_}) $WinPEDrivers += @($Task.WinPEDrivers | Where-Object {$_}) $WinPEScriptsPE += @($Task.WinPEScriptsPE | Where-Object {$_}) $WinPEScriptsRE += @($Task.WinPEScriptsRE | Where-Object {$_}) $WinPEScriptsSE += @($Task.WinPEScriptsSE | Where-Object {$_}) $WinPEExtraFilesPE += @($Task.WinPEExtraFilesPE | Where-Object {$_}) $WinPEExtraFilesRE += @($Task.WinPEExtraFilesRE | Where-Object {$_}) $WinPEExtraFilesSE += @($Task.WinPEExtraFilesSE | Where-Object {$_}) $WinPEADKPE += @($Task.WinPEADKPE | Where-Object {$_}) $WinPEADKRE += @($Task.WinPEADKRE | Where-Object {$_}) $WinPEADKSE += @($Task.WinPEADKSE | Where-Object {$_}) if ($Task.SetAllIntl) {$SetAllIntl = $Task.SetAllIntl} if ($Task.LangSetInputLocale) {$SetInputLocale = $Task.LangSetInputLocale} if ($Task.LangSetSKUIntlDefaults) {$SetSKUIntlDefaults = $Task.LangSetSKUIntlDefaults} if ($Task.LangSetSetupUILang) {$SetSetupUILang = $Task.LangSetSetupUILang} if ($Task.LangSetSysLocale) {$SetSysLocale = $Task.LangSetSysLocale} if ($Task.LangSetUILang) {$SetUILang = $Task.LangSetUILang} if ($Task.LangSetUILangFallback) {$SetUILangFallback = $Task.LangSetUILangFallback} if ($Task.LangSetUserLocale) {$SetUserLocale = $Task.LangSetUserLocale} $LanguageFeatures += @($Task.LanguageFeature | Where-Object {$_}) $LanguagePacks += @($Task.LanguagePack | Where-Object {$_}) $LanguageInterfacePacks += @($Task.LanguageInterfacePack | Where-Object {$_}) $LocalExperiencePacks += @($Task.LocalExperiencePacks | Where-Object {$_}) $LanguageCopySources += @($Task.LanguageCopySources | Where-Object {$_}) } } if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { if ($EnableNetFX.IsPresent) {$EnableNetFX3 = $true} if ((Get-IsContentPacksEnabled) -and ($SelectContentPacks.IsPresent)) { $ContentPacks = (Get-TaskContentPacks -Select).Name } Show-TaskInfo } #=================================================================================================== Write-Verbose '19.1.1 Set Proper Paths' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia') { if (Test-Path "$SetOSDBuilderPathOSImport\$($Bird.Name)") {$OSMediaPath = "$SetOSDBuilderPathOSImport\$($Bird.Name)"} if (Test-Path "$SetOSDBuilderPathOSMedia\$($Bird.Name)") {$OSMediaPath = "$SetOSDBuilderPathOSMedia\$($Bird.Name)"} } $OSImagePath = "$OSMediaPath\OS\sources\install.wim" if (!(Test-Path "$OSMediaPath\WindowsImage.txt")) { Write-Host '========================================================================================' -ForegroundColor DarkGray if ($null -eq $OSMediaPath) { Write-Warning "Unable to find an OSMedia to use" } else { Write-Warning "$OSMediaPath is not a valid OSMedia Directory" } Return } if (!(Test-Path "$OSImagePath")) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "$OSImagePath is not a valid Windows Image" Return } #=================================================================================================== Write-Verbose '19.1.1 Get Windows Image Information' #=================================================================================================== $OSImageIndex = 1 $WindowsImage = Get-WindowsImage -ImagePath "$OSImagePath" -Index $OSImageIndex | Select-Object -Property * $OSImageName = $($WindowsImage.ImageName) $OSImageName = $OSImageName -replace '\(', '' $OSImageName = $OSImageName -replace '\)', '' $OSImageDescription = $($WindowsImage.ImageDescription) $OSArchitecture = $($WindowsImage.Architecture) if ($OSArchitecture -eq '0') {$OSArchitecture = 'x86'} if ($OSArchitecture -eq '6') {$OSArchitecture = 'ia64'} if ($OSArchitecture -eq '9') {$OSArchitecture = 'x64'} if ($OSArchitecture -eq '12') {$OSArchitecture = 'x64 ARM'} $OSEditionID = $($WindowsImage.EditionId) $OSInstallationType = $($WindowsImage.InstallationType) $OSLanguages = $($WindowsImage.Languages) $OSVersion = $($WindowsImage.Version) $OSMajorVersion = $($WindowsImage.MajorVersion) $OSMinorVersion = $($WindowsImage.MinorVersion) $OSBuild = $($WindowsImage.Build) $OSSPBuild = $($WindowsImage.SPBuild) $OSSPLevel = $($WindowsImage.SPLevel) $OSImageBootable = $($WindowsImage.ImageBootable) $OSWIMBoot = $($WindowsImage.WIMBoot) $OSCreatedTime = $($WindowsImage.CreatedTime) $OSModifiedTime = $($WindowsImage.ModifiedTime) Show-MediaImageInfoOS #=================================================================================================== Write-Verbose '19.1.1 Validate Registry CurrentVersion.xml' #=================================================================================================== $RegValueCurrentBuild = $null if (Test-Path "$OSMediaPath\info\xml\CurrentVersion.xml") { $RegKeyCurrentVersion = Import-Clixml -Path "$OSMediaPath\info\xml\CurrentVersion.xml" $ReleaseId = $($RegKeyCurrentVersion.ReleaseId) $RegValueCurrentBuild = $($RegKeyCurrentVersion.CurrentBuild) if ($ReleaseId -gt 2009) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "OSDBuilder does not currently support this version of Windows ... Check for an updated version" } } #=================================================================================================== Write-Verbose '19.1.1 Set ReleaseId' #=================================================================================================== if ($null -ne $RegValueCurrentBuild) {$OSBuild = $RegValueCurrentBuild} if ($null -eq $ReleaseId) { if ($OSBuild -eq 7600) {$ReleaseId = 7600} if ($OSBuild -eq 7601) {$ReleaseId = 7601} if ($OSBuild -eq 9600) {$ReleaseId = 9600} if ($OSBuild -eq 10240) {$ReleaseId = 1507} if ($OSBuild -eq 14393) {$ReleaseId = 1607} if ($OSBuild -eq 15063) {$ReleaseId = 1703} if ($OSBuild -eq 16299) {$ReleaseId = 1709} if ($OSBuild -eq 17134) {$ReleaseId = 1803} if ($OSBuild -eq 17763) {$ReleaseId = 1809} #if ($OSBuild -eq 18362) {$ReleaseId = 1903} #if ($OSBuild -eq 18363) {$ReleaseId = 1909} #if ($OSBuild -eq 18990) {$ReleaseId = 2001} } #=================================================================================================== # Operating System #=================================================================================================== $UpdateOS = '' if ($OSMajorVersion -eq 10) { if ($OSInstallationType -notlike "*Server*") {$UpdateOS = 'Windows 10'} #elseif ($OSMBuild -ge 17763) {$UpdateOS = 'Windows Server 2019'} elseif ($OSImageName -match '2016') {$UpdateOS = 'Windows Server 2016'} elseif ($OSImageName -match '2019') {$UpdateOS = 'Windows Server 2019'} else {$UpdateOS = 'Windows Server'} } elseif ($OSMajorVersion -eq 6) { if ($OSInstallationType -like "*Server*") { if ($OSVersion -like "6.3*") { $UpdateOS = 'Windows Server 2012 R2' } elseif ($OSVersion -like "6.2*") { $UpdateOS = 'Windows Server 2012' Write-Warning "This Operating System is not supported" Return } elseif ($OSVersion -like "6.1*") { $UpdateOS = 'Windows Server 2008 R2' Write-Warning "This Operating System is not supported" Return } else { Write-Warning "This Operating System is not supported" } } else { if ($OSVersion -like "6.3*") { $UpdateOS = 'Windows 8.1' Write-Warning "This Operating System is not supported" Return } elseif ($OSVersion -like "6.2*") { $UpdateOS = 'Windows 8' Write-Warning "This Operating System is not supported" Return } elseif ($OSVersion -like "6.1*") { $UpdateOS = 'Windows 7' } else { Write-Warning "This Operating System is not supported" } } } #=================================================================================================== Write-Verbose '19.1.1 WorkingName and WorkingPath' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { $WorkingName = "build$((Get-Date).ToString('yyMMddhhmm'))" $WorkingPath = "$SetOSDBuilderPathOSBuilds\$WorkingName" } else { $WorkingName = "build$((Get-Date).ToString('yyMMddhhmm'))" $WorkingPath = "$SetOSDBuilderPathOSMedia\$WorkingName" } #=================================================================================================== Write-Verbose '19.1.1 Remove Existing OSMedia' #=================================================================================================== if (Test-Path $WorkingPath) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "$WorkingPath will be replaced!" } #=================================================================================================== # Template Content #=================================================================================================== if (Get-IsTemplatesEnabled) { #=================================================================================================== # OSBuild # Driver Templates #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and (Test-Path $SetOSDBuilderPathTemplates) -and (!($SkipTemplates.IsPresent))) { $DriverTemplates = Get-OSTemplateDrivers if ($DriverTemplates) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "OSBuild Template Driver Directories (Applied)" -ForegroundColor Green foreach ($Item in $DriverTemplates) {Write-Host $Item.FullName -ForegroundColor Gray} } } #=================================================================================================== # OSBuild # ExtraFiles Templates #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and (Test-Path $SetOSDBuilderPathTemplates) -and (!($SkipTemplates.IsPresent))) { #Write-Host "OSBuild Template ExtraFiles Directories (Searched)" -ForegroundColor Green $ExtraFilesTemplates = Get-OSTemplateExtraFiles if ($ExtraFilesTemplates) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "OSBuild Template ExtraFiles Files (Applied)" -ForegroundColor Green foreach ($Item in $ExtraFilesTemplates) {Write-Host $Item.FullName -ForegroundColor Gray} } } #=================================================================================================== # OSBuild # Registry REG Templates #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and (Test-Path $SetOSDBuilderPathTemplates) -and (!($SkipTemplates.IsPresent))) { #Write-Host "OSBuild Template Registry REG Directories (Searched)" -ForegroundColor Green $RegistryTemplatesReg = Get-OSTemplateRegistryReg if ($RegistryTemplatesReg) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "OSBuild Template Registry REG Files (Applied)" -ForegroundColor Green foreach ($Item in $RegistryTemplatesReg) {Write-Host $Item.FullName -ForegroundColor Gray} } } #=================================================================================================== # OSBuild # Registry XML Templates #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and (Test-Path $SetOSDBuilderPathTemplates) -and (!($SkipTemplates.IsPresent))) { #Write-Host "OSBuild Template Registry XML Directories (Searched)" -ForegroundColor Green $RegistryTemplatesXml = Get-OSTemplateRegistryXml if ($RegistryTemplatesXml) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "OSBuild Template Registry XML Files (Applied)" -ForegroundColor Green foreach ($Item in $RegistryTemplatesXml) {Write-Host $Item.FullName -ForegroundColor Gray} } } #=================================================================================================== # OSBuild # Script Templates #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and (Test-Path $SetOSDBuilderPathTemplates) -and (!($SkipTemplates.IsPresent))) { #Write-Host "OSBuild Template Script Directories (Searched)" -ForegroundColor Green $ScriptTemplates = Get-OSTemplateScripts if ($ScriptTemplates) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "OSBuild Template Script Files (Applied)" -ForegroundColor Green foreach ($Item in $ScriptTemplates) {Write-Host $Item.FullName -ForegroundColor Gray} } } } #=================================================================================================== # OSDSUS (Microsoft Updates) #=================================================================================================== # OSDUpdates #=================================================================================================== $OSDUpdates = $AllOSDUpdates if ($SkipUpdates.IsPresent) {$OSDUpdates = @()} $OSDUpdates = $OSDUpdates | Where-Object {$_.UpdateArch -eq $OSArchitecture} $OSDUpdates = $OSDUpdates | Where-Object {$_.UpdateOS -eq $UpdateOS} $OSDUpdates = $OSDUpdates | Where-Object {($_.UpdateBuild -eq $ReleaseId) -or ($_.UpdateBuild -eq '')} $OSDUpdates = $OSDUpdates | Sort-Object -Property CreationDate #=================================================================================================== # Update Filters #=================================================================================================== if ($OSInstallationType -match 'Core'){$OSDUpdates = $OSDUpdates | Where-Object {$_.UpdateGroup -ne 'AdobeSU'}} if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia' -and $OSMajorVersion -eq 10) { $OSDUpdates = $OSDUpdates | Where-Object {$_.UpdateGroup -ne ''} $OSDUpdates = $OSDUpdates | Where-Object {$_.UpdateGroup -ne 'Optional'} } #=================================================================================================== # Include Exclude #=================================================================================================== if ($IncludeKB) { $OSDUpdates = $OSDUpdates | Where-Object {$_.KBNumber -in $IncludeKB} } if ($Include) { $OSDUpdates = $OSDUpdates | Where-Object {$_.UpdateGroup -in $Include} } if ($Exclude) { $OSDUpdates = $OSDUpdates | Where-Object {$_.UpdateGroup -notin $Exclude} } if ($ExcludeKB){ $OSDUpdates = $OSDUpdates | Where-Object {$_.KBNumber -notin $ExcludeKB} } #=================================================================================================== # SelectUpdates #=================================================================================================== if ($SelectUpdates.IsPresent) {$OSDUpdates = $OSDUpdates | Out-GridView -PassThru -Title 'Select Updates to Apply and press OK'} $MissingUpdate = $false #=================================================================================================== # Updates Downloaded and Not Downloaded #=================================================================================================== $UpdatesDownloaded = @() $UpdatesDownloaded = $OSDUpdates | Where-Object {$_.OSDStatus -eq 'Downloaded'} | Sort-Object CreationDate if ($UpdatesDownloaded) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "OSDSUS (Microsoft Updates) Downloaded" -ForegroundColor Green foreach ($Update in $UpdatesDownloaded) { Write-Host "$($Update.CreationDate) - " -NoNewline Write-Host "$($Update.UpdateGroup) - " -NoNewline -ForegroundColor Cyan Write-Host "$($Update.Title)" } } $UpdatesNotDownloaded = @() $UpdatesNotDownloaded = $OSDUpdates | Where-Object {$_.OSDStatus -ne 'Downloaded'} #OSBuild does not automatically download Optional Updates for Windows 10 if ($OSMajorVersion -eq 10) {$UpdatesNotDownloaded = $UpdatesNotDownloaded | Where-Object {$_.UpdateGroup -ne ''} | Where-Object {$_.UpdateGroup -ne 'Optional'}} $UpdatesNotDownloadedOptional = @() $UpdatesNotDownloadedOptional = $OSDUpdates | Where-Object {$_.OSDStatus -ne 'Downloaded'} | Where-Object {$_.UpdateGroup -eq 'Optional'} if ($UpdatesNotDownloaded -or $UpdatesNotDownloadedOptional) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "OSDSUS (Microsoft Updates) Not Downloaded" -ForegroundColor Yellow foreach ($Update in $UpdatesNotDownloaded) { Write-Host "$($Update.CreationDate) - " -NoNewline Write-Host "$($Update.UpdateGroup) - " -NoNewline -ForegroundColor Cyan Write-Host "$($Update.Title)" } foreach ($Update in $UpdatesNotDownloadedOptional) { Write-Host "$($Update.CreationDate) - " -NoNewline Write-Host "$($Update.UpdateGroup) - " -NoNewline -ForegroundColor Cyan Write-Host "$($Update.Title)" } if ($Download.IsPresent) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "OSDSUS (Microsoft Updates) Download" -ForegroundColor Green if ($UpdatesNotDownloadedOptional){ Write-Host "Optional Updates are not automatically downloaded. Use the following command:" -ForegroundColor Yellow Write-Host "Get-DownOSDBuilder -UpdateOS '$UpdateOS' -UpdateBuild $ReleaseId -UpdateArch $OSArchitecture -UpdateGroup Optional -Download" -ForegroundColor Yellow } foreach ($Update in $UpdatesNotDownloaded) { Write-Host "$($Update.CreationDate) - $($Update.UpdateGroup) - $($Update.Title)" -ForegroundColor Cyan Get-OSDUpdateDownloads -OSDGuid $Update.OSDGuid } } } if ($UpdatesNotDownloaded -and (!($Download.IsPresent))) { $Execute = $false $MissingUpdate = $true } #=================================================================================================== # SetupDU #=================================================================================================== $OSDUpdateSetupDU = @() $OSDUpdateSetupDU = $OSDUpdates | Where-Object {$_.UpdateGroup -eq 'SetupDU'} #=================================================================================================== # ComponentDU #=================================================================================================== $OSDUpdateComponentDU = @() $OSDUpdateComponentDU = $OSDUpdates | Where-Object {$_.UpdateGroup -like "ComponentDU*"} #=================================================================================================== # SSU #=================================================================================================== $OSDUpdateSSU = @() $OSDUpdateSSU = $OSDUpdates | Where-Object {$_.UpdateGroup -eq 'SSU'} #=================================================================================================== # LCU #=================================================================================================== $OSDUpdateLCU = @() $OSDUpdateLCU = $OSDUpdates | Where-Object {$_.UpdateGroup -eq 'LCU'} #=================================================================================================== # AdobeSU #=================================================================================================== $OSDUpdateAdobeSU = @() if ($OSMajorVersion -eq 10) { $OSDUpdateAdobeSU = $OSDUpdates | Where-Object {$_.UpdateGroup -eq 'AdobeSU'} } #=================================================================================================== # DotNet #=================================================================================================== $OSDUpdateDotNet = @() if ($OSMajorVersion -eq 10) { $OSDUpdateDotNet = $OSDUpdates | Where-Object {$_.UpdateGroup -like "DotNet*"} } #=================================================================================================== # OSDBuilder Seven #=================================================================================================== $OSDUpdateWinSeven = @() if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia' -and $UpdateOS -eq 'Windows 7') { $OSDUpdateWinSeven = $OSDUpdates } #=================================================================================================== # OSDBuilder EightOne #=================================================================================================== $OSDUpdateWinEightOne = @() if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia' -and $UpdateOS -eq 'Windows 8.1') { $OSDUpdateWinEightOne = $OSDUpdates $OSDUpdateWinEightOne = $OSDUpdateWinEightOne | Where-Object {$_.UpdateGroup -ne 'SetupDU'} $OSDUpdateWinEightOne = $OSDUpdateWinEightOne | Where-Object {$_.UpdateGroup -notlike "ComponentDU*"} } #=================================================================================================== # OSDBuilder Twelve #=================================================================================================== $OSDUpdateWinTwelveR2 = @() if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia' -and $UpdateOS -eq 'Windows Server 2012 R2') { $OSDUpdateWinTwelveR2 = $OSDUpdates $OSDUpdateWinTwelveR2 = $OSDUpdateWinTwelveR2 | Where-Object {$_.UpdateGroup -ne 'SetupDU'} $OSDUpdateWinTwelveR2 = $OSDUpdateWinTwelveR2 | Where-Object {$_.UpdateGroup -notlike "ComponentDU*"} } #=================================================================================================== # Optional #=================================================================================================== $OSDUpdateOptional = @() if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and $OSMajorVersion -eq 10) { $OSDUpdateOptional = $OSDUpdates | Where-Object {($_.UpdateGroup -eq '') -or ($_.UpdateGroup -eq 'Optional')} } #=================================================================================================== # Update Check #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and $LatestOSMedia) { if ($LatestOSMedia.Updates -ne 'OK') { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "This OSMedia does not have the latest OSDSUS (Microsoft Updates)" Write-Warning "Use the following command before running New-OSBuild" Write-Warning "Update-OSMedia -Name `'$OSMediaName`' -Download -Execute" Write-Host '========================================================================================' -ForegroundColor DarkGray } } #=================================================================================================== # Execution Check #=================================================================================================== if ($MissingUpdate -eq $true) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "Execute is currently disabled as all Updates have not been downloaded" Write-Warning "You can automatically download required Updates by adding the -Download parameter" } elseif ($Execute -eq $false) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "Use the -Execute parameter to complete this task" } #=================================================================================================== if ($Execute.IsPresent) { #=================================================================================================== Write-Verbose '19.1.25 Remove Existing WorkingPath' #=================================================================================================== if (Test-Path $WorkingPath) { Write-Host '========================================================================================' -ForegroundColor DarkGray Remove-Item -Path "$WorkingPath" -Force -Recurse } #=================================================================================================== Write-Verbose '19.2.25 Set Variables' #=================================================================================================== $MountDirectory = Join-Path $SetOSDBuilderPathMount "os$((Get-Date).ToString('yyMMddhhmm'))" $MountWinPE = Join-Path $SetOSDBuilderPathMount "winpe$((Get-Date).ToString('yyMMddhhmm'))" $MountWinRE = Join-Path $SetOSDBuilderPathMount "winre$((Get-Date).ToString('yyMMddhhmm'))" $MountWinSE = Join-Path $SetOSDBuilderPathMount "setup$((Get-Date).ToString('yyMMddhhmm'))" $Info = Join-Path $WorkingPath 'info' $Logs = Join-Path $Info 'logs' $OS = Join-Path $WorkingPath 'OS' $WimTemp = Join-Path $WorkingPath "WimTemp" $WinPE = Join-Path $WorkingPath 'WinPE' $PEInfo = Join-Path $WinPE 'info' $PELogs = Join-Path $PEInfo 'logs' #=================================================================================================== Write-Verbose '19.1.1 Start Transcript' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray $ScriptName = $($MyInvocation.MyCommand.Name) $LogName = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$ScriptName.log" Start-Transcript -Path (Join-Path "$Info\logs" $LogName) | Out-Null #=================================================================================================== # Update-OSMedia and New-OSBuild #=================================================================================================== New-DirectoriesOSMedia Show-WorkingInfoOS Copy-MediaOperatingSystem #=================================================================================================== # WinPE #=================================================================================================== Update-SetupDUMEDIA Mount-WinPEwim -OSMediaPath "$WorkingPath" Mount-WinREwim -OSMediaPath "$WorkingPath" Mount-WinSEwim -OSMediaPath "$WorkingPath" #=================================================================================================== # WinPE ADK #=================================================================================================== $global:ReapplyLCU = $false $global:UpdateLanguageContent = $false Add-ContentADKWinPE Add-ContentADKWinRE Add-ContentADKWinSE Add-ContentPack -PackType PEADK Add-ContentPack -PackType PEADKLang #=================================================================================================== # WinPE DaRT #=================================================================================================== Expand-DaRTPE Add-ContentPack -PackType PEDaRT #=================================================================================================== # WinPE Updates #=================================================================================================== Update-ServicingStackPE Update-CumulativePE #=================================================================================================== # WinPE Content #=================================================================================================== Import-AutoExtraFilesPE Add-ContentExtraFilesPE Add-ContentDriversPE Add-ContentScriptsPE Add-ContentPack -PackType PEDrivers Add-ContentPack -PackType PEExtraFiles Add-ContentPack -PackType PEPoshMods Add-ContentPack -PackType PERegistry Add-ContentPack -PackType PEScripts #=================================================================================================== # Update-OSMedia and New-OSBuild #=================================================================================================== Update-SourcesPE -OSMediaPath "$WorkingPath" Save-PackageInventoryPE -OSMediaPath "$WorkingPath" if ($PauseDismountPE.IsPresent){[void](Read-Host 'Press Enter to Continue')} Dismount-WimsPE -OSMediaPath "$WorkingPath" Export-PEWims -OSMediaPath "$WorkingPath" Export-PEBootWim -OSMediaPath "$WorkingPath" Save-InventoryPE -OSMediaPath "$WorkingPath" #=================================================================================================== # Install.wim #=================================================================================================== $global:ReapplyLCU = $false Mount-InstallwimOS Set-WinREWimOS #=================================================================================================== # Install.wim UBR Pre-Update #=================================================================================================== Show-ActionTime Write-Host -ForegroundColor Green "OS: Mount Registry for UBR Information" $RegKeyCurrentVersion = Get-RegCurrentVersion -Path $MountDirectory if ($($RegKeyCurrentVersion.ReleaseId)) {$ReleaseId = $($RegKeyCurrentVersion.ReleaseId)} if ($($RegKeyCurrentVersion.CurrentBuild)) {$RegValueCurrentBuild = $($RegKeyCurrentVersion.CurrentBuild)} else {$RegValueCurrentBuild = $OSSPBuild} if ($($RegKeyCurrentVersion.UBR)) {$RegValueUbr = $($RegKeyCurrentVersion.UBR)} else {$RegValueUbr = $OSSPBuild} $UBR = "$RegValueCurrentBuild.$RegValueUbr" Save-RegistryCurrentVersionOS $UBRPre = $UBR #=================================================================================================== # Language Content #=================================================================================================== Add-LanguagePacksOS Add-ContentPack -PackType OSLanguagePacks Add-LanguageInterfacePacksOS Add-LanguageFeaturesOnDemandOS Add-ContentPack -PackType OSLanguageFeatures Add-LocalExperiencePacksOS Add-ContentPack -PackType OSLocalExperiencePacks Copy-MediaLanguageSources Add-ContentPack -PackType MEDIA if ($LanguagePacks -or $LanguageInterfacePacks -or $LanguageFeatures -or $LocalExperiencePacks -or ($global:UpdateLanguageContent -eq $true)) { Set-LanguageSettingsOS #Update-CumulativeOS -Force #if ($HideCleanupProgress.IsPresent) {Invoke-DismCleanupImage -HideCleanupProgress} else {Invoke-DismCleanupImage} } #=================================================================================================== # Optional Content #=================================================================================================== Add-ContentPack -PackType OSCapability Add-ContentPack -PackType OSPackages Add-WindowsPackageOS Add-FeaturesOnDemandOS #=================================================================================================== # Install.wim Updates #=================================================================================================== Update-ComponentOS Update-ServicingStackOS #=================================================================================================== # Install.wim UBR Post-Update #=================================================================================================== Show-ActionTime; Write-Host -ForegroundColor Green "OS: Update Build Revision $UBRPre (Pre-LCU)" if ($global:ReapplyLCU -eq $true) {Update-CumulativeOS -Force} else {Update-CumulativeOS} #=================================================================================================== # Update-OSMedia #=================================================================================================== Update-WindowsSevenOS Update-WindowsServer2012R2OS #=================================================================================================== # Install.wim UBR Post-Update #=================================================================================================== $RegKeyCurrentVersion = Get-RegCurrentVersion -Path $MountDirectory if ($($RegKeyCurrentVersion.ReleaseId)) {$ReleaseId = $($RegKeyCurrentVersion.ReleaseId)} if ($($RegKeyCurrentVersion.CurrentBuild)) {$RegValueCurrentBuild = $($RegKeyCurrentVersion.CurrentBuild)} else {$RegValueCurrentBuild = $OSSPBuild} if ($($RegKeyCurrentVersion.UBR)) {$RegValueUbr = $($RegKeyCurrentVersion.UBR)} else {$RegValueUbr = $OSSPBuild} $UBR = "$RegValueCurrentBuild.$RegValueUbr" Save-RegistryCurrentVersionOS Show-ActionTime Write-Host -ForegroundColor Green "OS: Update Build Revision $UBR (Post-LCU)" #=================================================================================================== # Update-OSMedia and New-OSBuild #=================================================================================================== Update-AdobeOS Update-DotNetOS Update-OptionalOS #=================================================================================================== # OneDriveSetup #=================================================================================================== if ($OSMajorVersion -eq 10 -and $OSInstallationType -eq 'Client') { Show-ActionTime Write-Host -ForegroundColor Green "OS: Update OneDriveSetup.exe" $OneDriveSetupDownload = $false $OneDriveSetup = Join-Path $GetOSDBuilderPathContentOneDrive 'OneDriveSetup.exe' if (!(Test-Path $OneDriveSetup)) {$OneDriveSetupDownload = $true} if (Test-Path $OneDriveSetup) { if (!(([System.Io.fileinfo]$OneDriveSetup).LastWriteTime.Date -ge [datetime]::Today )) { $OneDriveSetupDownload = $true } } <# if ($OneDriveSetupDownload -eq $true) { $WebClient = New-Object System.Net.WebClient Write-Host "Downloading to $OneDriveSetup" -ForegroundColor Gray $WebClient.DownloadFile('https://go.microsoft.com/fwlink/p/?LinkId=248256',"$OneDriveSetup") } #> if ($OSArchitecture -eq 'x86') { $OneDriveSetupInfo = Get-Item -Path "$MountDirectory\Windows\System32\OneDriveSetup.exe" | Select-Object -Property * Write-Host -ForegroundColor Gray " Existing Image Version $($($OneDriveSetupInfo).VersionInfo.ProductVersion)" if (Test-Path $OneDriveSetup) { robocopy "$GetOSDBuilderPathContentOneDrive" "$MountDirectory\Windows\System32" OneDriveSetup.exe /ndl /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-OneDriveSetup.log" | Out-Null $OneDriveSetupInfo = Get-Item -Path "$MountDirectory\Windows\System32\OneDriveSetup.exe" | Select-Object -Property * Write-Host -ForegroundColor Gray " Updating with Version $($($OneDriveSetupInfo).VersionInfo.ProductVersion)" } } else { $OneDriveSetupInfo = Get-Item -Path "$MountDirectory\Windows\SysWOW64\OneDriveSetup.exe" | Select-Object -Property * Write-Host -ForegroundColor Gray " Existing Image Version $($($OneDriveSetupInfo).VersionInfo.ProductVersion)" if (Test-Path $OneDriveSetup) { robocopy "$GetOSDBuilderPathContentOneDrive" "$MountDirectory\Windows\SysWOW64" OneDriveSetup.exe /ndl /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-OneDriveSetup.log" | Out-Null $OneDriveSetupInfo = Get-Item -Path "$MountDirectory\Windows\SysWOW64\OneDriveSetup.exe" | Select-Object -Property * Write-Host -ForegroundColor Gray " Updating with Version $($($OneDriveSetupInfo).VersionInfo.ProductVersion)" } } Write-Host -ForegroundColor Cyan " To update OneDriveSetup.exe use one of the following commands:" Write-Host -ForegroundColor Cyan " Get-DownOSDBuilder -ContentDownload 'OneDriveSetup Enterprise'" Write-Host -ForegroundColor Cyan " Get-DownOSDBuilder -ContentDownload 'OneDriveSetup Production'" } #=================================================================================================== # DismCleanupImage #=================================================================================================== if ($global:ReapplyLCU -eq $true) {Update-CumulativeOS -Force} if ($HideCleanupProgress.IsPresent) {Invoke-DismCleanupImage -HideCleanupProgress} else {Invoke-DismCleanupImage} #=================================================================================================== # Content #=================================================================================================== Enable-WindowsOptionalFeatureOS Enable-NetFXOS Remove-AppxProvisionedPackageOS Remove-WindowsPackageOS Remove-WindowsCapabilityOS Disable-WindowsOptionalFeatureOS Add-ContentDriversOS Add-ContentExtraFilesOS Add-ContentStartLayout Add-ContentUnattend Add-ContentScriptsOS Import-RegistryRegOS Import-RegistryXmlOS Add-ContentPack -PackType OSDrivers Add-ContentPack -PackType OSExtraFiles Add-ContentPack -PackType OSPoshMods Add-ContentPack -PackType OSRegistry Add-ContentPack -PackType OSScripts Add-ContentPack -PackType OSStartLayout #=================================================================================================== # Updates #=================================================================================================== #Update-ServicingStackOS -Force #=================================================================================================== # Mirror OSMedia and OSBuild #=================================================================================================== Save-AutoExtraFilesOS -OSMediaPath "$WorkingPath" Save-SessionsXmlOS -OSMediaPath "$WorkingPath" Save-InventoryOS -OSMediaPath "$WorkingPath" #=================================================================================================== # Dismount #=================================================================================================== if ($PauseDismountOS.IsPresent){[void](Read-Host 'Press Enter to Continue')} Dismount-InstallwimOS Export-InstallwimOS #=================================================================================================== Write-Verbose '19.1.1 OS: Export Configuration' #=================================================================================================== Show-ActionTime Write-Host -ForegroundColor Green "OS: Export Configuration to $WorkingPath\WindowsImage.txt" $GetWindowsImage = @() $GetWindowsImage = Get-WindowsImage -ImagePath "$OS\sources\install.wim" -Index 1 | Select-Object -Property * Write-Verbose "========== SPBuild: $($GetWindowsImage.Build).$($GetWindowsImage.SPBuild)" if ($OSVersion -like "6.*") { Write-Verbose '========== Windows 6.x' $UBR = "$($GetWindowsImage.Build).$($GetWindowsImage.SPBuild)" } Write-Verbose "========== UBR: $UBR" $GetWindowsImage | Add-Member -Type NoteProperty -Name "UBR" -Value $UBR $GetWindowsImage | Out-File "$WorkingPath\WindowsImage.txt" $GetWindowsImage | Out-File "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage.txt" $GetWindowsImage | Export-Clixml -Path "$Info\xml\Get-WindowsImage.xml" $GetWindowsImage | Export-Clixml -Path "$Info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage.xml" $GetWindowsImage | ConvertTo-Json | Out-File "$Info\json\Get-WindowsImage.json" $GetWindowsImage | ConvertTo-Json | Out-File "$Info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage.json" (Get-Content "$WorkingPath\WindowsImage.txt") | Where-Object {$_.Trim(" `t")} | Set-Content "$WorkingPath\WindowsImage.txt" #=================================================================================================== # OSD-Export #=================================================================================================== #Save-WindowsImageContentPE #=================================================================================================== Write-Verbose '19.3.17 UBR Validation' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia') { if ($UBRPre -eq $UBR) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning 'The Update Build Revision did not change after Windows Updates' Write-Warning 'There may have been an issue applying the Latest Cumulative Update if this was not expected' } } if (!($UBR)) { Write-Host '========================================================================================' -ForegroundColor DarkGray $UBR = $((Get-Date).ToString('yyMMddhhmm')) Write-Warning 'Could not determine a UBR' } #=================================================================================================== Write-Verbose '19.1.1 Remove Temporary Files' #=================================================================================================== if (Test-Path "$WimTemp") {Remove-Item -Path "$WimTemp" -Force -Recurse | Out-Null} if (Test-Path "$MountDirectory") {Remove-Item -Path "$MountDirectory" -Force -Recurse | Out-Null} if (Test-Path "$MountWinRE") {Remove-Item -Path "$MountWinRE" -Force -Recurse | Out-Null} if (Test-Path "$MountWinPE") {Remove-Item -Path "$MountWinPE" -Force -Recurse | Out-Null} if (Test-Path "$MountWinSE") {Remove-Item -Path "$MountWinSE" -Force -Recurse | Out-Null} #=================================================================================================== Write-Verbose '19.1.1 Set New Name' #=================================================================================================== $OSImageName = $($GetWindowsImage.ImageName) $OSImageName = $OSImageName -replace '\(', '' $OSImageName = $OSImageName -replace '\)', '' $OSArchitecture = $($GetWindowsImage.Architecture) if ($OSArchitecture -eq '0') {$OSArchitecture = 'x86'} if ($OSArchitecture -eq '6') {$OSArchitecture = 'ia64'} if ($OSArchitecture -eq '9') {$OSArchitecture = 'x64'} if ($OSArchitecture -eq '12') {$OSArchitecture = 'x64 ARM'} $OSBuild = $($GetWindowsImage.Build) $ReleaseId = $null if (Test-Path "$Info\xml\CurrentVersion.xml") { $RegKeyCurrentVersion = Import-Clixml -Path "$Info\xml\CurrentVersion.xml" $ReleaseId = $($RegKeyCurrentVersion.ReleaseId) } if ($OSBuild -eq 7600) {$ReleaseId = 7600} if ($OSBuild -eq 7601) {$ReleaseId = 7601} if ($OSBuild -eq 9600) {$ReleaseId = 9600} if ($OSBuild -eq 10240) {$ReleaseId = 1507} if ($OSBuild -eq 14393) {$ReleaseId = 1607} if ($OSBuild -eq 15063) {$ReleaseId = 1703} if ($OSBuild -eq 16299) {$ReleaseId = 1709} if ($OSBuild -eq 17134) {$ReleaseId = 1803} if ($OSBuild -eq 17763) {$ReleaseId = 1809} #if ($OSBuild -eq 18362) {$ReleaseId = 1903} if ($OSMajorVersion -eq 10) { if ($WorkingName -like "build*") {$NewOSMediaName = "$OSImageName $OSArchitecture $ReleaseId $UBR"} } else { if ($WorkingName -like "build*") {$NewOSMediaName = "$OSImageName $OSArchitecture $UBR"} } $OSLanguages = $($GetWindowsImage.Languages) $NewOSMediaName = "$NewOSMediaName $OSLanguages" if ($($OSLanguages.count) -eq 1) {$NewOSMediaName = $NewOSMediaName.replace(' en-US','')} if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { if ($CustomName) {$NewOSMediaName = "$CustomName $UBR"} } if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia') {$NewOSMediaPath = "$SetOSDBuilderPathOSMedia\$NewOSMediaName"} if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {$NewOSMediaPath = "$SetOSDBuilderPathOSBuilds\$NewOSMediaName"} #=================================================================================================== # 19.1.1 Rename Build Directory #=================================================================================================== if (Test-Path $NewOSMediaPath) { $yyMMddhhmm = $((Get-Date).ToString('yyMMddhhmm')) Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning 'Trying to rename the Build directory, but it already exists' Write-Warning "Appending $yyMMddhhmm to the directory Name" Write-Host '========================================================================================' -ForegroundColor DarkGray $NewOSMediaName = "$NewOSMediaName $yyMMddhhmm" if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia') {$NewOSMediaPath = "$SetOSDBuilderPathOSMedia\$NewOSMediaName"} if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {$NewOSMediaPath = "$SetOSDBuilderPathOSBuilds\$NewOSMediaName"} } #=================================================================================================== # OSD-Export #=================================================================================================== Save-WindowsImageContentOS Save-VariablesOSD #=================================================================================================== # OSDBuilder Media' #=================================================================================================== if ($CreateISO.IsPresent) {New-OSDBuilderISO -FullName "$WorkingPath"} if ($OSDVHD.IsPresent) {New-OSDBuilderVHD -FullName "$WorkingPath"} if ($OSDInfo.IsPresent) {Show-OSDBuilderInfo -FullName "$WorkingPath"} #=================================================================================================== # Complete Update #=================================================================================================== Show-ActionTime Write-Host -ForegroundColor Green "Media: Renaming ""$WorkingPath"" to ""$NewOSMediaName""" Write-Host '========================================================================================' -ForegroundColor DarkGray Stop-Transcript | Out-Null try { Rename-Item -Path "$WorkingPath" -NewName "$NewOSMediaName" } catch { Write-Warning "Could not rename the the Build directory ... Waiting 30 seconds ..." Start-Sleep -Seconds 30 } if (Test-Path "$WorkingPath") { try { Rename-Item -Path "$WorkingPath" -NewName "$NewOSMediaName" } catch { Write-Warning "Could not rename the the Build directory ..." } } <# if (Test-Path "$NewOSMediaPath") { Return (Get-OSMedia | Where-Object {$_.FullName -eq $NewOSMediaPath}) } else { Return (Get-OSMedia | Where-Object {$_.FullName -eq $WorkingPath}) } #> } } } END { #Write-Host '========================================================================================' -ForegroundColor DarkGray #Write-Host -ForegroundColor Green "$($MyInvocation.MyCommand.Name) END" } } |