Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Deploy, evaluate, and manage AI agents end-to-end on Microsoft Azure AI Foundry
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
foundry-agent/create/scripts/verify-environment.ps1
1<#2.SYNOPSIS3Verifies the local environment for creating a hosted Foundry agent with `azd ai`.4.DESCRIPTION5Runs all the read-only checks in one pass and prints a single concise summary,6so the agent does not have to run (and reason over) each azd command separately.78Output lines are prefixed with [OK], [WARN], or [ACTION].9Exit code is 0 when no blocking actions remain, 1 when at least one [ACTION] is required.10.EXAMPLE11./verify-environment.ps112#>1314$ErrorActionPreference = "Stop"15$actionRequired = $false1617function Note-Ok { param([string]$m) Write-Output "[OK] $m" }18function Note-Warn { param([string]$m) Write-Output "[WARN] $m" }19function Note-Action { param([string]$m) Write-Output "[ACTION] $m"; $script:actionRequired = $true }2021function Get-AzdJson {22param([string[]]$AzdArgs)23try {24$raw = & azd @AzdArgs 2>$null25if (-not $raw) { return $null }26return ($raw | ConvertFrom-Json -ErrorAction Stop)27} catch {28return $null29}30}3132# Refresh PATH to pick up recently-installed tools (e.g. azd installed in same session)33$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")3435# 1. azd present + version36# Check PATH first, then probe common install locations (winget, MSI, chocolatey)37if (-not (Get-Command azd -ErrorAction SilentlyContinue)) {38$azdFallbackPaths = @(39"$env:LOCALAPPDATA\Programs\Azure Dev CLI"40"$env:ProgramFiles\Azure Dev CLI"41"${env:ProgramFiles(x86)}\Azure Dev CLI"42"$env:USERPROFILE\.azd\bin"43)44$found = $false45foreach ($dir in $azdFallbackPaths) {46if (Test-Path "$dir\azd.exe") {47$env:Path = "$dir;$env:Path"48Note-Warn "azd found at '$dir' but was not on PATH. Added automatically for this session."49$found = $true50break51}52}53if (-not $found) {54Note-Action "Azure Developer CLI (azd) is not installed. Install it from https://aka.ms/azd-install, then re-run."55Write-Output ""56Write-Output "Summary: azd missing -- cannot continue."57exit 158}59}6061$verJson = Get-AzdJson @("version", "--output", "json")62$azdVersion = if ($verJson -and $verJson.azd -and $verJson.azd.version) { $verJson.azd.version } else { "unknown" }63Note-Ok "azd installed (version $azdVersion)."6465# 2. Required extensions66$extRaw = (& azd extension list --output json 2>$null) -join "`n"67foreach ($ext in @("azure.ai.agents", "azure.ai.projects")) {68if ($extRaw -match [regex]::Escape($ext)) {69Note-Ok "Extension '$ext' is installed."70} else {71Note-Action "Extension '$ext' is missing. Run: azd extension install $ext"72}73}7475# 3. Auth status76& azd auth login --check-status *> $null77if ($LASTEXITCODE -eq 0) {78Note-Ok "Logged in to azd."79} else {80Note-Action "Not logged in. Ask the user to run 'azd auth login' (it opens a browser; never run it for them)."81}8283# 4. Foundry project endpoint (optional at this stage)84# Short-circuit when there's no azd project in cwd: `azd ai project show` / `agent show`85# would just return nothing after a ~3s subprocess each.86if (-not (Test-Path "azure.yaml")) {87Note-Warn "No Foundry project endpoint set yet. A new project will be created at provision/deploy time, or supply an existing project resource ID."88Note-Ok "No agent deployed yet. Proceed with create."89} else {90$projectJson = Get-AzdJson @("ai", "project", "show", "--output", "json")91$endpoint = $null92if ($projectJson) {93foreach ($k in @("endpoint", "projectEndpoint", "aiProjectEndpoint")) {94if ($projectJson.PSObject.Properties.Name -contains $k -and $projectJson.$k) {95$endpoint = $projectJson.$k96break97}98}99}100if ($endpoint) {101Note-Ok "Foundry project endpoint configured: $endpoint"102} else {103Note-Warn "No Foundry project endpoint set yet. A new project will be created at provision/deploy time, or supply an existing project resource ID."104}105106# 5. Agent deployment status107$agentJson = Get-AzdJson @("ai", "agent", "show", "--output", "json")108if ($agentJson) {109$status = if ($agentJson.PSObject.Properties.Name -contains "status" -and $agentJson.status) { $agentJson.status } else { "unknown" }110switch ($status) {111{ $_ -in @("active", "deployed") } { Note-Ok "An agent is already deployed (status: $status). Skip to deploy.md to redeploy, or tools to add a tool." }112"not_deployed" { Note-Ok "No agent deployed yet (status: not_deployed). Proceed with create." }113default { Note-Warn "Agent status: $status." }114}115} else {116Note-Ok "No agent deployed yet. Proceed with create."117}118}119120Write-Output ""121if ($actionRequired) {122Write-Output "Summary: action required -- resolve the [ACTION] items above before continuing."123exit 1124} else {125Write-Output "Summary: environment ready for 'azd ai' hosted-agent creation."126exit 0127}128