Private/Copy-OSDCloud.media.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 |
function Copy-OSDCloud.media { [CmdletBinding(PositionalBinding = $false)] param ( [Parameter(ValueFromPipelineByPropertyName = $true)] [string]$WorkspacePath = (Join-Path $env:TEMP (Get-Random)) ) #================================================= # Start the Clock #================================================= $StartTime = Get-Date #================================================= # Require WinOS #================================================= if ((Get-OSDGather -Property IsWinPE)) { Write-Warning "$($MyInvocation.MyCommand) cannot be run from WinPE" Break } #================================================= # Require Admin Rights #================================================= if ((Get-OSDGather -Property IsAdmin) -eq $false) { Write-Warning "$($MyInvocation.MyCommand) requires Admin Rights ELEVATED" Break } #================================================= # Require cURL #================================================= if (-NOT (Test-Path "$env:SystemRoot\System32\curl.exe")) { Write-Warning "$($MyInvocation.MyCommand) could not find $env:SystemRoot\System32\curl.exe" Write-Warning "Get a newer Windows version!" Break } #================================================= # Set VerbosePreference #================================================= $CurrentVerbosePreference = $VerbosePreference $VerbosePreference = 'Continue' #================================================= # Get Adk Paths #================================================= $AdkPaths = Get-AdkPaths if ($null -eq $AdkPaths) { Write-Warning "Could not get ADK going, sorry" Break } #================================================= # Get WinPE.wim #================================================= $WorkspacePath = "$env:ProgramData\OSDCloud" $WimSourcePath = $AdkPaths.WimSourcePath if (-NOT (Test-Path $WimSourcePath)) { Write-Warning "Could not find $WimSourcePath, sorry" Break } $PathWinPEMedia = $AdkPaths.PathWinPEMedia $DestinationMedia = Join-Path $WorkspacePath 'Media' Write-Verbose "Copying ADK Media to $DestinationMedia" robocopy "$PathWinPEMedia" "$DestinationMedia" *.* /e /ndl /xj /ndl /np /nfl /njh /njs $DestinationSources = Join-Path $DestinationMedia 'sources' if (-NOT (Test-Path "$DestinationSources")) { New-Item -Path "$DestinationSources" -ItemType Directory -Force -ErrorAction Stop | Out-Null } $BootWim = Join-Path $DestinationSources 'boot.wim' Write-Verbose "Copying ADK Boot.wim to $BootWim" Copy-Item -Path $WimSourcePath -Destination $BootWim -Force #================================================= # Mount-MyWindowsImage #================================================= $MountMyWindowsImage = Mount-MyWindowsImage $BootWim $MountPath = $MountMyWindowsImage.Path #================================================= # Add Packages #================================================= $ErrorActionPreference = 'Ignore' $WinPEOCs = $AdkPaths.WinPEOCs Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-WMI.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-WMI_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-HTA.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-HTA_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-NetFx.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-NetFx_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-Scripting.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-Scripting_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-PowerShell.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-PowerShell_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-SecureStartup.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-SecureStartup_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-DismCmdlets.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-DismCmdlets_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-Dot3Svc.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-Dot3Svc_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-EnhancedStorage.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-EnhancedStorage_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-FMAPI.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-GamingPeripherals.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-PPPoE.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-PPPoE_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-PlatformId.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-PmemCmdlets.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-PmemCmdlets_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-RNDIS.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-RNDIS_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-SecureBootCmdlets.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-StorageWMI.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-StorageWMI_en-us.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\WinPE-WDS-Tools.cab" Add-WindowsPackage -Path $MountPath -PackagePath "$WinPEOCs\en-us\WinPE-WDS-Tools_en-us.cab" #================================================= # cURL #================================================= Write-Verbose "Adding curl.exe to $MountPath" if (Test-Path "$env:SystemRoot\System32\curl.exe") { robocopy "$env:SystemRoot\System32" "$MountPath\Windows\System32" curl.exe /ndl /nfl /njh /njs /b } else { Write-Warning "Could not find $env:SystemRoot\System32\curl.exe" Write-Warning "You must be using an old version of Windows" } #================================================= # PowerShell Execution Policy #================================================= Write-Verbose "Setting PowerShell ExecutionPolicy to Bypass in $MountPath" Set-WindowsImageExecutionPolicy -Path $MountPath -ExecutionPolicy Bypass #================================================= # Enable PowerShell Gallery #================================================= Write-Verbose "Enabling PowerShell Gallery support in $MountPath" Enable-PEWindowsImagePSGallery -Path $MountPath #================================================= # Save WIM #================================================= $MountMyWindowsImage | Dismount-MyWindowsImage -Save #================================================= # Restore VerbosePreference #================================================= $VerbosePreference = $CurrentVerbosePreference #================================================= # Complete #================================================= $EndTime = Get-Date $TimeSpan = New-TimeSpan -Start $StartTime -End $EndTime Write-Host -ForegroundColor DarkGray "================================================" Write-Host -ForegroundColor Yellow "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) $($MyInvocation.MyCommand.Name) " -NoNewline Write-Host -ForegroundColor Cyan "Completed in $($TimeSpan.ToString("mm' minutes 'ss' seconds'"))" #================================================= # Return #================================================= Return Get-Item -Path "$(Get-OSDCloudTemplate)\Media" #================================================= } |