-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathcleanup.ps1
More file actions
54 lines (46 loc) · 1.97 KB
/
cleanup.ps1
File metadata and controls
54 lines (46 loc) · 1.97 KB
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
#!/usr/bin/env pwsh
# cleanup.ps1 — Clean up Azure resources and local configuration
# Removes Azure deployment, clears environment variables, and deletes local artifacts.
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
Write-Host "`n=== Generative AI for Beginners .NET — Cleanup ===" -ForegroundColor Cyan
$cleanedUp = @()
# --- Delete Azure resources ---
Write-Host "`nDeleting Azure resources with 'azd down --purge --force'..." -ForegroundColor Yellow
try {
azd down --purge --force
if ($LASTEXITCODE -eq 0) {
$cleanedUp += "Azure resources deleted"
Write-Host "Azure resources deleted successfully." -ForegroundColor Green
}
} catch {
Write-Host "ERROR: Failed to run 'azd down --purge --force'." -ForegroundColor Red
exit 1
}
# --- Delete local .azure folder ---
$azurePath = ".azure"
if (Test-Path $azurePath) {
Write-Host "`nRemoving local '$azurePath' folder..." -ForegroundColor Yellow
Remove-Item -Path $azurePath -Recurse -Force
$cleanedUp += "Local .azure folder deleted"
Write-Host "'$azurePath' folder removed." -ForegroundColor Green
}
# --- Clear User Secrets ---
$secretsId = "genai-beginners-dotnet"
Write-Host "`nClearing User Secrets (--id $secretsId)..." -ForegroundColor Yellow
try {
dotnet user-secrets clear --id $secretsId
$cleanedUp += "User Secrets cleared ($secretsId)"
Write-Host " Cleared: User Secrets ($secretsId)" -ForegroundColor Green
} catch {
Write-Host " WARNING: Could not clear User Secrets" -ForegroundColor Yellow
}
# --- Print cleanup summary ---
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host " Cleanup Summary:" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
foreach ($item in $cleanedUp) {
Write-Host " ✓ $item" -ForegroundColor Green
}
Write-Host "========================================`n" -ForegroundColor Cyan
Write-Host "Cleanup complete!" -ForegroundColor Green