Public/OSDCloud/Select-AutoPilotJson.ps1
<#
.SYNOPSIS Searches for AutoPilot Jsons and allows you to select one .DESCRIPTION Searches for AutoPilot Jsons and allows you to select one .LINK https://osd.osdeploy.com/module/functions/autopilotjson .NOTES 21.3.12 Initial Release #> function Select-AutoPilotJson { [CmdletBinding()] param () $AutoPilotConfiguration = $null $AutoPilotJsons = @() $AutoPilotJsons = Get-PSDrive -PSProvider FileSystem | % {Get-ChildItem "$($_.Name):\*" -Include AutoPilot*.json -File -ErrorAction Ignore} | % {Get-Content $_ | ConvertFrom-Json} | Sort-Object Comment_File if ($AutoPilotJsons) { foreach ($Item in $AutoPilotJsons) { $i++ $Item | Add-Member -NotePropertyName "Number" -NotePropertyValue "$i" Write-Host "[$i]" -ForegroundColor Green -NoNewline Write-Host " $($Item.Comment_File)" Write-Host "$($Item.CloudAssignedTenantDomain) ZtdCorrelationId: $($Item.ZtdCorrelationId)" Write-Host "" } #Write-Host "[S]" -ForegroundColor Green -BackgroundColor Black -NoNewline #Write-Host "Skip AutoPilotConfigurationFile.json" do { $AutoPilotJson = Read-Host -Prompt "Type the Number to select an AutoPilot Profile to apply (AutoPilotConfigurationFile.json), or S to Skip" } until ( ((($AutoPilotJson -ge 0) -and ($AutoPilotJson -in $AutoPilotJsons.Number)) -or ($AutoPilotJson -eq 'S')) ) if ($AutoPilotJson -ne 'S') { $AutoPilotConfiguration = $AutoPilotJsons | Where-Object {$_.Number -eq $AutoPilotJson} $AutoPilotConfiguration = $AutoPilotConfiguration | Select-Object -Property * -ExcludeProperty Number } Return $AutoPilotConfiguration } } |