Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml 创建gui以解锁锁定的帐户_Xaml_Powershell - Fatal编程技术网

Xaml 创建gui以解锁锁定的帐户

Xaml 创建gui以解锁锁定的帐户,xaml,powershell,Xaml,Powershell,因此,从小事开始,我想找到一个IP地址,如果一个帐户已经在我的服务器上注销,我已经制作了GUI,它很好,但是按钮不起作用,知道我哪里出错了吗 理论上,它应该返回一个包含IP地址、时间戳和日期的字符串,但我是power shell的新手,所以我不是100%确定我在做什么,如果有任何帮助,我们将不胜感激 inputXML = @" <Window x:Class="UnlockerGui.MainWindow" xmlns="http://schemas.microsoft.c

因此,从小事开始,我想找到一个IP地址,如果一个帐户已经在我的服务器上注销,我已经制作了GUI,它很好,但是按钮不起作用,知道我哪里出错了吗

理论上,它应该返回一个包含IP地址、时间戳和日期的字符串,但我是power shell的新手,所以我不是100%确定我在做什么,如果有任何帮助,我们将不胜感激

inputXML = @"
<Window x:Class="UnlockerGui.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="538.433">
    <Grid HorizontalAlignment="Left" Width="538" Margin="0,0,-8,-21" RenderTransformOrigin="0.295,0.552">
        <Grid.RowDefinitions>
            <RowDefinition Height="101*"/>
            <RowDefinition Height="239*"/>
        </Grid.RowDefinitions>
        <TextBox x:Name="TxtName" HorizontalAlignment="Left" Height="45" Margin="10,10,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="177"/>
        <Button Grid.Row="0" x:Name="BtnSearch" Content="Search" HorizontalAlignment="Left" Margin="192,10,0,0" VerticalAlignment="Top" Width="271" Height="45"/>
        <ListBox x:Name="LbResults" HorizontalAlignment="Left" Height="246" Margin="10,60,0,0" Grid.Row="0"
                 Grid.RowSpan="2" VerticalAlignment="Top" Width="504"/>

    </Grid>
</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."}
 #===========================================================================
# Load XAML 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
#===========================================================================

#Sample entry of how to add data to a field

#$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})

Function Get-Data{
param([string]$Localusername)
string[] $results1 =  
Get-WinEvent -ComputerName SERVERNAME1 -FilterHashtable @{logname='security';id=4771;data=$Localusername} |
Select-Object -Property timecreated,
@{Name='computername';expression={$_.properties[6].value.Split(':')[3]}}


foreach($string in $results1)
{
     $WPFLbResults.Items.Add($results1[$string])
}

string[] $results2 =  
Get-WinEvent -ComputerName SERVERNAME2 -FilterHashtable @{logname='security';id=4771;data=$Localusername} |
Select-Object -Property timecreated,
@{Name='computername';expression={$_.properties[6].value.Split(':')[3]}}

foreach($string in $results2)
{
     $WPFLbResults.Items.Add($results2[$string])
}

string[] $results3 =  
Get-WinEvent -ComputerName SERVERNAME3 -FilterHashtable @{logname='security';id=4771;data=$Localusername} |
Select-Object -Property timecreated,
@{Name='computername';expression={$_.properties[6].value.Split(':')[3]}}

foreach($string in $results3)
{
     $WPFLbResults.Items.Add($results3[$string])
}

}

#===========================================================================
# Shows the form
#===========================================================================

$Form.ShowDialog() | Out-Null
$WPFBtnSearch.Add_Click({
$username = $WPFTxtName.Text
Get-Data($username)
})
inputXML=@”
"@

$inputXML=$inputXML-replace'mc:Ignorable=“d”、'-replace“x:N”、'N'-replace'^
$WPFBtnSearch
没有在任何地方定义,即使定义了,在调用
$Form.ShowDialog()
@MathiasR.Jessen之前也需要调用
add\u Click()
,对不对?在这种情况下,请遵循我的第二个建议顶部的XAML具有
BtnSearch
而不是
WPFBtnSearch
它可以工作!!!!!谢谢你,我很感激,多年来一直在努力解决这个问题!