Public/OSDCloud/Select-OSDCloudAutopilotFile.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
<#
.SYNOPSIS
Selects Autopilot Profiles
 
.DESCRIPTION
Selects Autopilot Profiles
 
.LINK
https://osdcloud.osdeploy.com
 
.NOTES
21.3.12 Initial Release
#>

function Select-OSDCloudAutopilotFile {
    [CmdletBinding()]
    param ()

    $i = $null
    $FindOSDCloudFile = Find-OSDCloudFile -Name "*.json" -Path '\OSDCloud\Autopilot\Profiles\' | Sort-Object FullName
    $FindOSDCloudFile = $FindOSDCloudFile | Where-Object {$_.FullName -notlike "C*"}


    if ($FindOSDCloudFile) {
        $AutopilotProfiles = foreach ($Item in $FindOSDCloudFile) {
            $i++
            $JsonConfiguration = Get-Content -Path $Item.FullName | ConvertFrom-Json

            $ObjectProperties = @{
                Selection           = $i
                Name                = $Item.Name
                FullName            = $Item.FullName
                Profile             = $JsonConfiguration.Comment_File
                Tenant              = $JsonConfiguration.CloudAssignedTenantDomain
                ZtdCorrelationId    = $JsonConfiguration.ZtdCorrelationId
                FullContent         = $JsonConfiguration
            }
            New-Object -TypeName PSObject -Property $ObjectProperties
        }

        $AutopilotProfiles | Select-Object -Property Selection, Profile, FullName | Format-Table | Out-Host

        #if ($Global:OSDCloudZTI -eq $true) {
        # $AutopilotProfiles = $AutopilotProfiles | Where-Object {$_.Selection -eq 1}
        #}
        #else {
            do {
                $SelectReadHost = Read-Host -Prompt "Enter the Selection of the Autopilot Profile to apply, or press S to Skip"
            }
            until (((($SelectReadHost -ge 0) -and ($SelectReadHost -in $AutopilotProfiles.Selection -or ($SelectReadHost -eq 'S')))))
            
            if ($SelectReadHost -eq 'S') {
                Return $false
            }
            $AutopilotProfiles = $AutopilotProfiles | Where-Object {$_.Selection -eq $SelectReadHost}
        #}

        Return Get-Item $AutopilotProfiles.FullName
    }
}