-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate-Dbatools.ps1
More file actions
61 lines (51 loc) · 2.6 KB
/
Copy pathUpdate-Dbatools.ps1
File metadata and controls
61 lines (51 loc) · 2.6 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
55
56
57
58
59
60
61
# Update-Dbatools.ps1
# Downloads/updates the dbatools PowerShell module into the app's .\dbatools folder.
# Run this script manually or call it from the publish pipeline to keep dbatools current.
#
# Usage:
# .\Update-Dbatools.ps1 # downloads to .\dbatools next to the script
# .\Update-Dbatools.ps1 -TargetPath "C:\MyApp" # downloads to C:\MyApp\dbatools
param(
[string]$TargetPath = $PSScriptRoot
)
$modulePath = Join-Path $TargetPath "dbatools"
Write-Host "dbatools updater" -ForegroundColor Cyan
Write-Host "Target: $modulePath" -ForegroundColor Gray
# Check for internet connectivity
try {
$null = [System.Net.Dns]::GetHostEntry("www.powershellgallery.com")
} catch {
Write-Warning "Cannot reach PowerShell Gallery. Check internet connectivity."
exit 1
}
# Ensure NuGet provider is available (needed for Save-Module on some systems)
if (-not (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
Write-Host "Installing NuGet provider..." -ForegroundColor Yellow
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser | Out-Null
}
# Create target directory
if (-not (Test-Path $modulePath)) {
New-Item -ItemType Directory -Path $modulePath -Force | Out-Null
Write-Host "Created $modulePath" -ForegroundColor Green
}
Write-Host "Downloading dbatools (this may take a few minutes, ~160 MB)..." -ForegroundColor Yellow
try {
# PINNED. `Save-Module` with no -RequiredVersion takes whatever PowerShell Gallery serves
# today, so two machines running this script a week apart get different modules and the app
# inherits a dependency nobody chose. 2.8.4 is the version this repo is verified against
# (PS Gallery, 2026-07-31). dbatools 2.8.0 shipped breaking changes to
# Install-DbaMaintenanceSolution parameters and dropped SQL 2005; the app calls neither, but
# that is exactly the kind of change a floating install would have absorbed silently.
# To move the pin: bump it HERE and in PowerShellService.PinnedDbatoolsVersion, in one commit.
Save-Module -Name dbatools -Path $modulePath -RequiredVersion 2.8.4 -Force -ErrorAction Stop
Write-Host "dbatools downloaded successfully." -ForegroundColor Green
# Show what was downloaded
$versions = Get-ChildItem (Join-Path $modulePath "dbatools") -Directory -ErrorAction SilentlyContinue
if ($versions) {
Write-Host "Installed version: $($versions[-1].Name)" -ForegroundColor Cyan
}
} catch {
Write-Error "Failed to download dbatools: $_"
exit 1
}
Write-Host "Done. Restart the app to use the updated module." -ForegroundColor Green