Я создал приложение WPF XAML, которое использует PowerShell в фоновом режиме для выполнения каких-либо задач.Вот фрагмент кода, который я написал.
function Add-ControlVariables {
New-Variable -Name 'Login' -Value $window.FindName('Login') -Scope 1 -Force
New-Variable -Name 'AvailableSubscriptions' -Value $window.FindName('AvailableSubscriptions') -Scope 1 -Force
New-Variable -Name 'AvailableResourceGroups' -Value $window.FindName('AvailableResourceGroups') -Scope 1 -Force
New-Variable -Name 'AvailablLogicApps' -Value $window.FindName('AvailablLogicApps') -Scope 1 -Force
}
function Load-Xaml {
[xml]$xaml = Get-Content -Path $PSScriptRoot\Azure.xaml
$manager = New-Object System.Xml.XmlNamespaceManager -ArgumentList $xaml.NameTable
$manager.AddNamespace("x", "http://schemas.microsoft.com/winfx/2006/xaml");
$xaml.SelectNodes("//*[@x:Name='Login']", $manager)[0].RemoveAttribute('Click')
$xaml.SelectNodes("//*[@x:Name='AvailableSubscriptions']", $manager)[0].RemoveAttribute('SelectionChanged')
$xaml.SelectNodes("//*[@x:Name='AvailableResourceGroups']", $manager)[0].RemoveAttribute('SelectionChanged')
$xaml.SelectNodes("//*[@x:Name='AvailablLogicApps']", $manager)[0].RemoveAttribute('SelectionChanged')
$xamlReader = New-Object System.Xml.XmlNodeReader $xaml
[Windows.Markup.XamlReader]::Load($xamlReader)
}
function Set-EventHandlers {
$Login.add_Click({
param([System.Object]$sender,[System.Windows.RoutedEventArgs]$e)
Login($sender,$e)
Connect-AzureRmAccount
$AvailableSubscriptions.ItemsSource = Get-AzureRmSubscription | Select-Object -ExpandProperty Name
})
$AvailableSubscriptions.add_SelectionChanged({
param([System.Object]$sender,[System.Windows.Controls.SelectionChangedEventArgs]$e)
AvailableSubscriptions_SelectionChanged($sender,$e)
})
$AvailableResourceGroups.add_SelectionChanged({
param([System.Object]$sender,[System.Windows.Controls.SelectionChangedEventArgs]$e)
$resourceGroupName = $sender.SelectedItem
$AvailablLogicApps.ItemsSource = Get-AzureRmResource -ResourceType "Microsoft.Logic/workflows" -ResourceGroupName $resourceGroupName | Select-Object -ExpandProperty Name
})
$AvailablLogicApps.add_SelectionChanged({
param([System.Object]$sender,[System.Windows.Controls.SelectionChangedEventArgs]$e)
})
}
$window = Load-Xaml
Add-ControlVariables
Set-EventHandlers
function AvailableSubscriptions_SelectionChanged
{
param($sender, $e)
$subscription = $sender.SelectedItem
Select-AzureRmSubscription -SubscriptionName $subscription
$AvailableResourceGroups.ItemsSource = Get-AzureRmResourceGroup | Select-Object -ExpandProperty ResourceGroupName
}
$window.ShowDialog()
Вот интерфейс.Я хочу, чтобы подписки были указаны как одна вещь.Имя подписки отображается в виде отдельных символов.
https://imgur.com/a/BY424pz