diff --git a/Docs/Test-OSDCloudFileWim.md b/Docs/Test-OSDCloudFileWim.md new file mode 100644 index 000000000..d50573c59 --- /dev/null +++ b/Docs/Test-OSDCloudFileWim.md @@ -0,0 +1,49 @@ +--- +external help file: OSD-help.xml +Module Name: OSD +online version: https://github.com/OSDeploy/OSD/tree/master/Docs +schema: 2.0.0 +--- + +# Test-OSDCloudFileWim + +## SYNOPSIS +Tests if a .wim, .esd, or .install.swm file exists in the specified directory. + +## SYNTAX + +``` +Test-OSDCloudFileWim [-ImageFileItem] [] +``` + +## DESCRIPTION +This function checks whether a .wim, .esd, or .install.swm file exists at the given path. It uses the Get-PSDrive cmdlet to search through available file system drives (excluding C:\ and X:\), and then it attempts to find a matching file. If a matching file is found, the function returns the file object. If no such file exists, the function returns nothing. +## EXAMPLES + +### Example 1 - Check if a WIM file exists +```powershell +PS C:\> Test-OSDCloudFileWim -ImageFileItem "D:\images\install.wim" +``` +This command will search for install.wim in the D:\images\ directory. If it exists, it returns the file object. + +## PARAMETERS + +### -ImageFileItem +The path to the image file or directory (e.g., D:\images\install.wim). The function will check for .wim, .esd, or .install.swm files in the specified path. + +```yaml +Type: String +Required: true +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). +## INPUTS +## OUTPUTS +## NOTES +## RELATED LINKS +[https://github.com/OSDeploy/OSD/tree/master/Docs](https://github.com/OSDeploy/OSD/tree/master/Docs) diff --git a/Docs/Test-OSDCloudImageIndex.md b/Docs/Test-OSDCloudImageIndex.md new file mode 100644 index 000000000..310d8955e --- /dev/null +++ b/Docs/Test-OSDCloudImageIndex.md @@ -0,0 +1,59 @@ +--- +external help file: OSD-help.xml +Module Name: OSD +online version: https://github.com/OSDeploy/OSD/tree/master/Docs +schema: 2.0.0 +--- + +# Test-OSDCloudImageIndex + +## SYNOPSIS +Tests if a specific Image Index exists within a provided image file. + +## SYNTAX + +``` +Test-OSDCloudImageIndex [-ImagePath] [-Index] [] +``` + +## DESCRIPTION +This function checks whether a given Image Index exists within the specified image file. It uses the Get-WindowsImage cmdlet to query the image file and validate if the specified index is available. If the index exists, it returns the ImageIndex value; otherwise, it will return nothing. + +## EXAMPLES + +### Example 1 - Check if an image index exists +```powershell +PS C:\> Test-OSDCloudImageIndex -ImagePath "install.wim" -Index 3 +``` +This command will check if the image index 3 exists in the image file located at \OSDCloud\OS\install.wim. If it exists, the function will return the ImageIndex value. + +## PARAMETERS + +### -ImagePath +The path to the image file (e.g., D:\OSCloud\OS\install.wim or D:\OSCloud\OS\images\image.esd). + +```yaml +Type: String +Required: true +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` +### -Index +The index of the image within the image file to check. +```yaml +Type: Int +Required: true +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). +## INPUTS +## OUTPUTS +## NOTES +## RELATED LINKS +[https://github.com/OSDeploy/OSD/tree/master/Docs](https://github.com/OSDeploy/OSD/tree/master/Docs) diff --git a/Public/OSDCloudTS/Test-OSDCloudFileWim.ps1 b/Public/OSDCloudTS/Test-OSDCloudFileWim.ps1 new file mode 100644 index 000000000..967548e09 --- /dev/null +++ b/Public/OSDCloudTS/Test-OSDCloudFileWim.ps1 @@ -0,0 +1,42 @@ +<# +.SYNOPSIS +Test if WIM file exists + +.DESCRIPTION +Test if WIM file exists + +.LINK +https://github.com/OSDeploy/OSD/tree/master/Docs +#> +function Test-OSDCloudFileWim { + [CmdletBinding()] + param ( + + [Parameter(Mandatory = $true)] + [string]$ImageFileItem + + ) + + $Name = Split-Path $ImageFileItem -Leaf + $Path = Split-Path $ImageFileItem + + + $Result = Get-PSDrive -PSProvider FileSystem | ForEach-Object { + # Exclude C:\ and X:\ drives + if ($_.Name -notin @('C', 'X')) { + $item = Get-Item "$($_.Name):$("\OSDCloud\OS\$($Path)\$($Name)")" -Filter "*.wim,*.esd,*.install.swm" -Force -ErrorAction SilentlyContinue + + # If we have found an item, return it + if ($item) { + return $item + } + } + } + + If ($Result){ + + Return Get-Item (Join-Path $Result.Directory $Result.Name) + + } + +} diff --git a/Public/OSDCloudTS/Test-OSDCloudImageIndex.ps1 b/Public/OSDCloudTS/Test-OSDCloudImageIndex.ps1 new file mode 100644 index 000000000..06d63b740 --- /dev/null +++ b/Public/OSDCloudTS/Test-OSDCloudImageIndex.ps1 @@ -0,0 +1,30 @@ +<# +.SYNOPSIS +Test if Image Index exists + +.DESCRIPTION +Test if Image Index exists + +.LINK +https://github.com/OSDeploy/OSD/tree/master/Docs +#> + +function Test-OSDCloudImageIndex { + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + [string]$ImagePath, + + [Parameter(Mandatory = $true)] + [int]$Index + ) + + $Image = Get-WindowsImage -ImagePath $ImagePath -Index $Index -ErrorAction Ignore + + If ($Image){ + + Return $Image.ImageIndex + + } + +} diff --git a/Public/Start-OSDCloud.ps1 b/Public/Start-OSDCloud.ps1 index 443a4a607..bd4e82991 100644 --- a/Public/Start-OSDCloud.ps1 +++ b/Public/Start-OSDCloud.ps1 @@ -1,4 +1,4 @@ -function Start-OSDCloud { +function Start-OSDCloud { <# .SYNOPSIS Starts the OSDCloud Windows 10 or 11 Build Process from the OSD Module or a GitHub Repository @@ -110,6 +110,11 @@ [System.Management.Automation.SwitchParameter] $FindImageFile, + #Uses a specified WIM/ESD file + [Parameter(ParameterSetName = 'CustomImage')] + [System.String] + $ImageFileItem, + #Downloads a WIM file specified by the URK [Parameter(ParameterSetName = 'CustomImage')] [System.String] @@ -139,7 +144,7 @@ GetDiskFixed = $null GetFeatureUpdate = $null ImageFileFullName = $null - ImageFileItem = $null + ImageFileItem = $ImageFileItem #changed ImageFileName = $null ImageFileSource = $null ImageFileDestination = $null @@ -184,6 +189,7 @@ TimeStart = Get-Date ZTI = $ZTI } + #================================================= # Update Defaults #================================================= @@ -286,11 +292,42 @@ Write-Host -ForegroundColor DarkGray "ImageFileUrl: $($Global:StartOSDCloud.ImageFileUrl)" Write-Host -ForegroundColor DarkGray "OSImageIndex: $($Global:StartOSDCloud.OSImageIndex)" } - if ($PSBoundParameters.ContainsKey('FindImageFile')) { - $Global:StartOSDCloud.ImageFileItem = Select-OSDCloudFileWim + if ($PSBoundParameters.ContainsKey('FindImageFile') -or $PSBoundParameters.ContainsKey('ImageFileItem')) { + + if ($Global:StartOSDCloud.ImageFileItem){ + + $OsdCloudFileWimCheck = Test-OSDCloudFileWim -ImageFileItem $Global:StartOSDCloud.ImageFileItem + + If ($OsdCloudFileWimCheck){ + + $Global:StartOSDCloud.ImageFileItem = $OsdCloudFileWimCheck + + }else { + Write-Warning "ImageFileItem $($Global:StartOSDCloud.ImageFileItem) does not exists or is not a valid WIM, ESD or install.swm file, please select one from the list below.." + $Global:StartOSDCloud.ImageFileItem = Select-OSDCloudFileWim + } + + }else{ + $Global:StartOSDCloud.ImageFileItem = Select-OSDCloudFileWim + } if ($Global:StartOSDCloud.ImageFileItem) { - $Global:StartOSDCloud.OSImageIndex = Select-OSDCloudImageIndex -ImagePath $Global:StartOSDCloud.ImageFileItem.FullName + if ($Global:StartOSDCloud.OSImageIndex){ + + $OSImageIndexCheck = Test-OSDCloudImageIndex -ImagePath $Global:StartOSDCloud.ImageFileItem.FullName -Index $Global:StartOSDCloud.OSImageIndex + + If ($OSImageIndexCheck){ + + $Global:StartOSDCloud.OSImageIndex = $OSImageIndexCheck + + }else { + Write-Warning "OSImageIndex $($Global:StartOSDCloud.OSImageIndex) does not exists, please select one from the list below.." + $Global:StartOSDCloud.OSImageIndex = Select-OSDCloudImageIndex -ImagePath $Global:StartOSDCloud.ImageFileItem.FullName + } + + }else{ + $Global:StartOSDCloud.OSImageIndex = Select-OSDCloudImageIndex -ImagePath $Global:StartOSDCloud.ImageFileItem.FullName + } Write-Host -ForegroundColor DarkGray "ImageFileItem: $($Global:StartOSDCloud.ImageFileItem.FullName)" Write-Host -ForegroundColor DarkGray "OSImageIndex: $($Global:StartOSDCloud.OSImageIndex)" @@ -305,6 +342,7 @@ } } } + #================================================= # ParameterSet Default #=================================================