Skip to content

PowerShell

Mathieu Lavigne edited this page Dec 17, 2025 · 4 revisions

Variables

Tableau de paramètres

[string[]]$scripts = If ($dropSchema) {
    @("drop_schema.sql", "init.sql")
} Else {
    @("init.sql")
}
$fileParameters = $scripts | ForEach-Object { "--file=$_" }

Mots-de-passe

Paramètre :

param(
    ## Mot-de-passe
    [Parameter(mandatory = $true, HelpMessage = "Mot-de-passe")]
    [SecureString]
    $password
)

Déchiffrement pour obtenir le mot-de-passe en clair :

$password_clear = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($password))

Modifier l'historique

Modifier le fichier renvoyer par la commande :

(Get-PSReadlineOption).HistorySavePath

source

Statut

if (!$?) { exit } # Sort si la dernière commande a échoué (TODO : code d'erreur > 0 ?)
if (!$?) { throw "Erreur" } # Idem mais avec exception

Source | Source

Grep

cmd | Select-String "ma chaîne recherchée"

Clone this wiki locally