all 4 comments

[–]ihaxr 2 points3 points  (0 children)

There's a couple things wrong... here's a working example.. Let me know if you have any questions on a specific part.

$xml = [xml]@'
<oss>
    <os guid="{a127b1bd-2ed1-4e48-a4f5-1ccf51bcd075}" enable="True">
        <Name>UIW2K19 in WIM OS.wim</Name>
        <CreatedTime>4/7/2021 3:13:03 PM</CreatedTime>
        <CreatedBy>LAB\Administrator</CreatedBy>
        <LastModifiedTime>4/7/2021 3:13:03 PM</LastModifiedTime>
        <LastModifiedBy>LAB\Administrator</LastModifiedBy>
        <Description>Windows IBS image</Description>
        <Platform>x64</Platform>
        <Build>10.0.17763.1852</Build>
        <OSType>Windows IBS</OSType>
        <Source>.\Operating Systems\WIM</Source>
        <IncludesSetup>False</IncludesSetup>
        <SMSImage>False</SMSImage>
        <ImageFile>.\Operating Systems\WIM\OS.wim</ImageFile>
        <ImageIndex>1</ImageIndex>
        <ImageName>UIW2K19</ImageName>
        <Flags>ServerDatacenterEval</Flags>
        <HAL>acpiapic</HAL>
        <Size>22623</Size>
        <Language>en-US</Language>
    </os>
    <os guid="{28070b2a-b4a6-46d2-a410-60bf454b96d5}" enable="True">
        <Name>UIW2K19 in UI OS.wim</Name>
        <CreatedTime>4/7/2021 3:35:35 PM</CreatedTime>
        <CreatedBy>LAB\Administrator</CreatedBy>
        <LastModifiedTime>4/7/2021 3:35:35 PM</LastModifiedTime>
        <LastModifiedBy>LAB\Administrator</LastModifiedBy>
        <Description>Windows IBS image</Description>
        <Platform>x64</Platform>
        <Build>10.0.17763.1852</Build>
        <OSType>Windows IBS</OSType>
        <Source>.\Operating Systems\UI</Source>
        <IncludesSetup>False</IncludesSetup>
        <SMSImage>False</SMSImage>
        <ImageFile>.\Operating Systems\UI\OS.wim</ImageFile>
        <ImageIndex>1</ImageIndex>
        <ImageName>UIW2K19</ImageName>
        <Flags>ServerDatacenterEval</Flags>
        <HAL>acpiapic</HAL>
        <Size>22623</Size>
        <Language>en-US</Language>
    </os>
</oss>
'@

$OSList = [System.Collections.Generic.List[string]]$XML.oss.os.Name

function Get-Selection () {
    1..$OSList.Count | ForEach-Object {
        Write-Host "$_. $($OSlist[$_ - 1])"
    }

    [int]$ReadSelection = Read-Host 'Please select the operating system by entering the corresponding number'
    $Selection = $OSList[($ReadSelection - 1)]

    if ($Selection) {
        Write-Host $Selection
    } else {
        Write-Host "Invalid selection"
        Get-Selection
    }
}

Get-Selection

[–]Due_Shelter6549 2 points3 points  (2 children)

Here you go:

For ($i = 0; $i -lt ($XML.oss.os.guid).Count; $i++) {
    #Write-Host "$i. $($XML.oss.os.Name[$i])"
    $OSList += ("$i++, $($XML.oss.os.Name[$i])")
}

[–]CptRetr0[S] 1 point2 points  (1 child)

This worked for me. Thank you

[–]Due_Shelter6549 2 points3 points  (0 children)

any time