创建一个gui来解锁已锁定的帐户

时间:2017-01-17 12:08:14

标签: xaml powershell

所以从小开始我想找到一个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)
})

0 个答案:

没有答案