- CLI PowerShell pour la gestion des sorties DALI adressable (ECxLightDaliA) - Action Read : rapport CSV des configurations (une ligne par output) - Action Write : modification des propriétés via POST JSON - Fallback curl.exe -k pour les automates avec problèmes SSL
98 lines
2.6 KiB
PowerShell
98 lines
2.6 KiB
PowerShell
# Module CsvHandler - Lecture/ecriture CSV automates
|
|
|
|
function Read-AutomateCsv {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[string]$CsvPath
|
|
)
|
|
|
|
if (-not (Test-Path $CsvPath)) {
|
|
throw "Fichier CSV introuvable : $CsvPath"
|
|
}
|
|
|
|
$rows = Import-Csv -Path $CsvPath -Delimiter ";"
|
|
Write-Log -Message "CSV charge : $($rows.Count) lignes depuis $CsvPath" -Level INFO
|
|
return $rows
|
|
}
|
|
|
|
function Get-BaseUrl {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[PSCustomObject]$Automate
|
|
)
|
|
|
|
$ip = $Automate."Current Ip"
|
|
$httpsPort = $Automate.HttpsPort
|
|
$httpPort = $Automate.HttpPort
|
|
|
|
# HTTPS si port > 0 et != -1
|
|
if ($httpsPort -and $httpsPort -ne "" -and [int]$httpsPort -gt 0 -and [int]$httpsPort -ne -1) {
|
|
if ([int]$httpsPort -eq 443) {
|
|
return "https://$ip"
|
|
}
|
|
return "https://${ip}:$httpsPort"
|
|
}
|
|
|
|
# HTTP si port > 0
|
|
if ($httpPort -and $httpPort -ne "" -and [int]$httpPort -gt 0 -and [int]$httpPort -ne -1) {
|
|
if ([int]$httpPort -eq 80) {
|
|
return "http://$ip"
|
|
}
|
|
return "http://${ip}:$httpPort"
|
|
}
|
|
|
|
return $null
|
|
}
|
|
|
|
function Get-Credentials {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[PSCustomObject]$Automate,
|
|
|
|
[string]$DefaultUsername = "admin",
|
|
[string]$DefaultPassword = ""
|
|
)
|
|
|
|
$username = $DefaultUsername
|
|
$password = $DefaultPassword
|
|
|
|
# Override depuis le CSV si colonnes presentes et renseignees
|
|
$props = $Automate.PSObject.Properties.Name
|
|
if ("Username" -in $props -and $Automate.Username -and $Automate.Username -ne "") {
|
|
$username = $Automate.Username
|
|
}
|
|
if ("Password" -in $props -and $Automate.Password -and $Automate.Password -ne "") {
|
|
$password = $Automate.Password
|
|
}
|
|
|
|
return @{
|
|
Username = $username
|
|
Password = $password
|
|
}
|
|
}
|
|
|
|
function Write-OutputCsv {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[array]$OutputRows,
|
|
|
|
[Parameter(Mandatory)]
|
|
[string]$OutputPath
|
|
)
|
|
|
|
# Creer le repertoire de sortie si necessaire
|
|
$outputDir = Split-Path $OutputPath -Parent
|
|
if ($outputDir -and -not (Test-Path $outputDir)) {
|
|
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
|
|
}
|
|
|
|
$OutputRows | Export-Csv -Path $OutputPath -Delimiter ";" -NoTypeInformation -Encoding UTF8
|
|
Write-Log -Message "CSV de sortie ecrit : $OutputPath ($($OutputRows.Count) lignes)" -Level SUCCESS
|
|
}
|
|
|
|
Export-ModuleMember -Function Read-AutomateCsv, Get-BaseUrl, Get-Credentials, Write-OutputCsv
|