53 lines
1.9 KiB
PowerShell
53 lines
1.9 KiB
PowerShell
# check-prerequisites.ps1
|
|
# Script per verificare i prerequisiti degli script PowerShell
|
|
|
|
function Write-Status {
|
|
param(
|
|
[string]$check,
|
|
[bool]$passed,
|
|
[string]$details
|
|
)
|
|
$status = if ($passed) { "[OK]" } else { "[ERRORE]" }
|
|
Write-Host "`n$check : $status"
|
|
if ($details) {
|
|
Write-Host $details
|
|
}
|
|
}
|
|
|
|
# Verifica versione PowerShell
|
|
$psVersion = $PSVersionTable.PSVersion
|
|
$psVersionOk = $psVersion.Major -ge 5 -and $psVersion.Minor -ge 1
|
|
Write-Status -check "Versione PowerShell" -passed $psVersionOk -details "Versione installata: $($psVersion.ToString())`nVersione minima richiesta: 5.1"
|
|
|
|
# Verifica System.Data assembly
|
|
try {
|
|
Add-Type -AssemblyName System.Data
|
|
$adoNetOk = $true
|
|
Write-Status -check "ADO.NET System.Data" -passed $true -details "Assembly System.Data caricato correttamente"
|
|
} catch {
|
|
$adoNetOk = $false
|
|
Write-Status -check "ADO.NET System.Data" -passed $false -details "Errore nel caricamento di System.Data"
|
|
}
|
|
|
|
# Verifica SqlCommand
|
|
try {
|
|
$connection = New-Object System.Data.SqlClient.SqlConnection
|
|
$command = New-Object System.Data.SqlClient.SqlCommand("", $connection)
|
|
$sqlCommandOk = $true
|
|
Write-Status -check "SQL Command" -passed $true -details "Creazione SqlCommand riuscita"
|
|
} catch {
|
|
$sqlCommandOk = $false
|
|
Write-Status -check "SQL Command" -passed $false -details "Errore nella creazione di SqlCommand: $($_.Exception.Message)"
|
|
}
|
|
|
|
# Riepilogo finale
|
|
$allOk = $psVersionOk -and $adoNetOk -and $sqlCommandOk
|
|
Write-Host "`n----------------------------------------"
|
|
$exitMessage = if ($allOk) { "Tutti i prerequisiti sono soddisfatti" } else { "ATTENZIONE: Alcuni prerequisiti non sono soddisfatti" }
|
|
$exitColor = if ($allOk) { "Green" } else { "Red" }
|
|
Write-Host $exitMessage -ForegroundColor $exitColor
|
|
Write-Host "----------------------------------------"
|
|
|
|
# Restituisci il risultato complessivo
|
|
exit ([int](-not $allOk))
|