|
$InformationPreference = "SilentlyContinue"
$ProgressPreference = "SilentlyContinue"
$VerbosePreference = "SilentlyContinue"
$WarningPreference = "SilentlyContinue"
$ErrorActionPreference = "SilentlyContinue"
# Chargement des composants WPF
Add-Type -AssemblyName PresentationFramework
# --- Contenu XAML ---
$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="ISE Plus" Height="600" Width="950" WindowStartupLocation="CenterScreen">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,0,0,10">
<TextBlock Name="LabelSearchText" VerticalAlignment="Center"/>
<TextBox Name="CmdSearchBox" Width="300" Margin="5,0"/>
</StackPanel>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<ListBox Name="CmdletList" Grid.Column="0" Margin="0,0,5,0"/>
<StackPanel Grid.Column="1">
<TextBlock Name="LabelSwitchText" FontWeight="Bold" Margin="0,0,0,5"/>
<ListBox Name="SwitchParamsList" Height="100"/>
<TextBlock Name="LabelInputText" FontWeight="Bold" Margin="10,10,0,5"/>
<ListBox Name="InputParamsList" Height="100"/>
<TextBlock Name="LabelValuesText" FontWeight="Bold" Margin="10,10,0,5"/>
<ListBox Name="ValuesList" Height="120"/>
<TextBlock Name="CmdletHelpLink" FontStyle="Italic" Foreground="Blue" TextDecorations="Underline" Cursor="Hand" Margin="10,10,0,0"/>
</StackPanel>
</Grid>
<Button Grid.Row="2" Name="CloseBtn" Width="100" HorizontalAlignment="Right"/>
</Grid>
</Window>
"@
# --- Contenu Langues.xml ---
$langXMLContent = @"
<Langues>
<Langue code="fr-FR">
<labelSwitch>Paramètres très booléens (switch) :</labelSwitch>
<labelInput>Paramètres avec valeurs attendues :</labelInput>
<labelValues>Valeurs possibles :</labelValues>
<labelSearch>Recherche de Cmdlet :</labelSearch>
<labelClose>Fermer</labelClose>
<typeString>Type attendu : Chaîne de caractères (ex : chemin, nom, texte)</typeString>
<typeInt>Type attendu : Entier (ex : 0, 1, 10…)</typeInt>
<typeBool>Type attendu : Vrai ou Faux</typeBool>
<typeDate>Type attendu : Date/Heure (ex : 2025-01-01)</typeDate>
<typeSecure>Type attendu : Mot de passe sécurisé</typeSecure>
<typeArray>Type attendu : Liste de chaînes (ex : a,b,c)</typeArray>
</Langue>
<Langue code="en-US">
<labelSwitch>Boolean parameters (switch):</labelSwitch>
<labelInput>Parameters with input values:</labelInput>
<labelValues>Possible values:</labelValues>
<labelSearch>Cmdlet Search:</labelSearch>
<labelClose>Close</labelClose>
<typeString>Expected type: String (e.g., path, name, text)</typeString>
<typeInt>Expected type: Integer (e.g., 0, 1, 10)</typeInt>
<typeBool>Expected type: Boolean (True or False)</typeBool>
<typeDate>Expected type: Date/Time (e.g., 2025-01-01)</typeDate>
<typeSecure>Expected type: Secure string (password)</typeSecure>
<typeArray>Expected type: Array of strings (e.g., a,b,c)</typeArray>
</Langue>
</Langues>
"@
# Lecture du XAML intégré
$reader = New-Object System.Xml.XmlTextReader([System.IO.StringReader]::new($xaml))
$reader.XmlResolver = $null
$window = [Windows.Markup.XamlReader]::Load($reader)
# --- Logique principale PowerShell ---
. {
# Add-Type already included above
$culture = (Get-Culture).Name
[xml]$langXML = $langXMLContent
$lang = $langXML.Langues.Langue | Where-Object { $_.code -eq $culture }
if (-not $lang) { $lang = $langXML.Langues.Langue | Where-Object { $_.code -eq "en-US" } }
$reader = New-Object System.Xml.XmlTextReader([System.IO.StringReader]::new($xaml))
$reader.XmlResolver = $null
$window = [Windows.Markup.XamlReader]::Load($reader)
$searchBox = $window.FindName("CmdSearchBox")
$cmdList = $window.FindName("CmdletList")
$switchParamsList = $window.FindName("SwitchParamsList")
$inputParamsList = $window.FindName("InputParamsList")
$valuesList = $window.FindName("ValuesList")
$labelSearchText = $window.FindName("LabelSearchText")
$labelSwitchText = $window.FindName("LabelSwitchText")
$labelInputText = $window.FindName("LabelInputText")
$labelValuesText = $window.FindName("LabelValuesText")
$closeBtn = $window.FindName("CloseBtn")
$cmdletHelpLink = $window.FindName("CmdletHelpLink")
$labelSearchText.Text = $lang.labelSearch
$labelSwitchText.Text = $lang.labelSwitch
$labelInputText.Text = $lang.labelInput
$labelValuesText.Text = $lang.labelValues
$closeBtn.Content = $lang.labelClose
$closeBtn.Add_Click({ $window.Close() })
if ($cmdletHelpLink) {
$cmdletHelpLink.Add_MouseLeftButtonUp({
if ($cmdletHelpLink.Text) {
Start-Process $cmdletHelpLink.Text
}
})
}
$allCmdlets = Get-Command -CommandType Cmdlet | Sort-Object Name
foreach ($cmd in $allCmdlets) {$null = $cmdList.Items.Add($cmd.Name)}
$searchBox.Add_TextChanged({
$filter = $searchBox.Text.ToLower()
$cmdList.Items.Clear()
foreach ($cmd in $allCmdlets) {
if ($cmd.Name.ToLower().Contains($filter)) {
$cmdList.Items.Add($cmd.Name)
}
}
})
$cmdList.Add_SelectionChanged({
$switchParamsList.Items.Clear()
$inputParamsList.Items.Clear()
$valuesList.Items.Clear()
$cmdName = $cmdList.SelectedItem
if ($cmdName) {
$cmdMeta = Get-Command $cmdName
$moduleName = $cmdMeta.ModuleName
$cmdLinkName = $cmdMeta.Name
if ($cmdletHelpLink -and $moduleName -and $cmdLinkName) {
$baseUrl = "https://learn.microsoft.com/powershell/module/"
$url = "$baseUrl$moduleName/$cmdLinkName".ToLower()
if ($cmdletHelpLink -and $moduleName -and $cmdLinkName) {
if ($moduleName -like "Microsoft.*" -or $moduleName -like "Az.*") {
$baseUrl = "https://learn.microsoft.com/powershell/module/"
$url = "$baseUrl$moduleName/$cmdLinkName".ToLower()
}
elseif ($moduleName -like "VMware.*") {
$baseUrl = "https://developer.vmware.com/docs/powercli/latest/"
$url = "$baseUrl$moduleName/commands/$cmdLinkName".ToLower()
}
else {
$url = ""
}
$cmdletHelpLink.Text = $url
$cmdletHelpLink.ToolTip = "Ouvrir la documentation"
}
}
foreach ($param in $cmdMeta.Parameters.Values) {
if ($param.ParameterType.Name -eq 'SwitchParameter') {
$switchParamsList.Items.Add($param.Name)
} else {
$inputParamsList.Items.Add($param.Name)
}
}
}
})
$inputParamsList.Add_SelectionChanged({
$valuesList.Items.Clear()
$cmdName = $cmdList.SelectedItem
$paramName = $inputParamsList.SelectedItem
if ($cmdName -and $paramName) {
$paramMeta = (Get-Command $cmdName).Parameters[$paramName]
$found = $false
foreach ($attr in $paramMeta.Attributes) {
if ($attr -is [System.Management.Automation.ValidateSetAttribute]) {
foreach ($val in $attr.ValidValues) {
$valuesList.Items.Add($val)
}
$found = $true
}
}
if (-not $found -and $paramMeta.ParameterType.IsEnum) {
[Enum]::GetNames($paramMeta.ParameterType) | ForEach-Object { $valuesList.Items.Add($_) }
$found = $true
}
if (-not $found) {
$typeName = $paramMeta.ParameterType.Name.ToLower()
$desc = switch ($typeName) {
"string" { $lang.typeString }
"int32" { $lang.typeInt }
"boolean" { $lang.typeBool }
"datetime" { $lang.typeDate }
"securestring" { $lang.typeSecure }
"string[]" { $lang.typeArray }
default { "Type attendu : $($paramMeta.ParameterType.Name)" }
}
$valuesList.Items.Add($desc)
}
}
})
$switchParamsList.Add_SelectionChanged({
$valuesList.Items.Clear()
$valuesList.Items.Add("[switch]")
})
$window.ShowDialog() | Out-Null
}
|
Commenter cet article