First of all, this is my first ever script with a XML GUI so it may be something very obvious that is missing. Basically, I'm doing a simple script where you choose a customer (translates to OU) and look for a username based on first name. However, the input window takes whatever it says when I run the script (so nothing) and never refresh after I filled in the form.
To clarify, when I click the button I want it to run through the form and see what has been written
If you guys need the XAML code let me know, the Powershell code looks like this:
Add-Type -AssemblyName PresentationFramework
$xamlFile = "$PSScriptRoot\MainWindow.xaml"
$inputXML = Get-Content $xamlFile -Raw
$inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
[XML]$XAML = $inputXML
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
try
{
$window = [Windows.Markup.XamlReader]::Load($reader)
}
catch
{
Write-Warning $_.Exception
throw
}
$xaml.SelectNodes("//*[@Name]") | ForEach-Object
{
try
{
Set-Variable -Name "var_$($_.Name)" -Value $window.FindName($_.Name) -ErrorAction Stop
}
catch
{
throw
}
}
Get-Variable var_*
$customer = $var_CustomerDropDown.Text
$firstName = $var_FirstnameBox.Text
$var_CreateButton.Add_Click
({
$var_LogText1.Text = ""
if ($customer -match "Customer1")
{
$result = Get-ADUser -Filter 'Name -like $firstName' | Select-Object -ExpandProperty Name
foreach ($item in $result)
{
$var_LogText1.Text = $var_LogText1.Text + "$item`n" + "Customer1`n"
}
}
if ($customer -match "Customer2")
{
$result = Get-ADUser -Filter 'Name -like $firstName' | Select-Object -ExpandProperty Name
foreach ($item in $result)
{
$var_LogText1.Text = $var_LogText1.Text + "$item`n" + "Customer2`n"
}
}
else
{
$var_LogText1.Text = "No customer chosen"
}
})
$Null = $window.ShowDialog()