我目前正在开发一个小工具,允许我使用PowerShell更改Active Directory中的域。目标是:
我尝试获取结果并传递其他标签,但没有显示。
我该怎么做?
我的代码(只是XAML的摘录):
$inputXML = @"
<Window x:Class="change_domain_v2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:change_domain_v2"
mc:Ignorable="d"
Title="MainWindow" Height="398.077" Width="957.692">
<TabControl x:Name="tabControl">
<TabItem Header="Migration">
<Grid Margin="0,-5,0,5" Background="White">
<Button x:Name="MigButton" Content="Migration" HorizontalAlignment="Left" Height="25" Margin="659,174,0,0" VerticalAlignment="Top" Width="172" Background="{DynamicResource {x:Static SystemColors.MenuHighlightBrushKey}}" Foreground="White" BorderBrush="Black"/>
<Button x:Name="buttonExit" Content="exit" HorizontalAlignment="Left" Margin="715,289,0,0" VerticalAlignment="Top" Width="75"/>
<Border BorderBrush="White" BorderThickness="1" HorizontalAlignment="Left" Height="212" Margin="350,97,0,0" VerticalAlignment="Top" Width="4" Background="{DynamicResource {x:Static SystemColors.ScrollBarBrushKey}}"/>
</Grid>
</TabItem>
<TabItem Header="LOGS">
<Grid>
<TextBlock x:Name="textBlock3" TextWrapping="Wrap" Text="TextBlock"/>
</Grid>
</TabItem>
</TabControl>
</Window>
"@
$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
#Read XAML
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
try {
$Form=[Windows.Markup.XamlReader]::Load( $reader )
} catch {
Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."
}
#===========================================================================
# Store Form Objects In PowerShell
#===========================================================================
$xaml.SelectNodes("//*[@Name]") | % {
Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)
}
Function Get-FormVariables {
if ($global:ReadmeDisplay -ne $true) {
Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow
$global:ReadmeDisplay = $true
}
Write-Host "Found the following interactable elements from our form" -ForegroundColor Cyan
Get-Variable WPF*
}
Get-FormVariables
#===========================================================================
# Actually make the objects work
#===========================================================================
#bouton EXIT
$WPFbuttonExit.add_click{$Form.Close()}
##########################
#change domain affiliation
##########################
## exemple commande : Add-Computer [-DomainName] <String> -Credential <PSCredential> [-ComputerName <String[]> ] [-Force] [-InformationAction <System.Management.Automation.ActionPreference]> {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend} ] [-InformationVariable <System.String]> ] [-LocalCredential <PSCredential> ] [-NewName <String> ] [-Options <JoinOptions> {AccountCreate | Win9XUpgrade | UnsecuredJoin | PasswordPass | DeferSPNSet | JoinWithNewName | JoinReadOnly | InstallInvoke} ]
# [-OUPath <String> ] [-PassThru] [-Restart] [-Server <String> ] [-UnjoinDomainCredential <PSCredential> ] [-Unsecure] [-Confirm] [-WhatIf] [ <CommonParameters>]
$WPFMigButton.add_Click({
$data = Add-Computer -DomainName test.corp -ComputerName $GetwmiSystem.Name -OUPath "ou=PDT-MI,dc=test,dc=corp" |
$WPFtextBlock3.Content = $data | Out-String
})
#Sample entry of how to add data to a field
#$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
#===========================================================================
# Shows the form
#===========================================================================
Write-Host "To show the form, run the following" -ForegroundColor Cyan
$Form.ShowDialog() | Out-Null