I have a script that I am trying to turn into a GUI.
There is a DataGrid in place with 2 columns and I have two TextBoxes that I would like to be able to type something into that populates the DataGrid.
box1 populates the first column, box2 populates the second column.
I need help with the KeyDown and the population parts.
#LoadForm
./LoadDialog.ps1 -XamlPath 'C:\Forms\ReNamer.xaml'
#EVENT Handler
$NewName
#Add old name manually
#################################PLEASE HELP HERE
$OldName.Add_KeyDown {
if ($_.KeyCode -eq 'Enter') {
$AddOldName.Invoke()
#Suppress sound from unexpected use of enter on keyPress/keyUp
$_.SuppressKeyPress = $true
}
}
$AddOldName.Add_Click({ AddOldName })
##$renameBtn.Add_Click({ $Form.Close() })
$Import.Add_Click({ GetCompList })
#Launch the window
$xamGUI.ShowDialog() | Out-Null
#Csv import button
Function GetCompList {
##File location
$csvfile = Import-Csv "C:\Sysinternals\rename.csv" |
Select-Object @{ n = "OldName"; e = { $_.OldName } }, @{ n = "NewName"; e = { $_.NewName } }
$csvfile | ForEach-Object { $dataGrid.AddChild($_) }
}
#Run Button
Function RenameComputers {
Write-Host "Renaming computer from: $o to: $n"
netdom renamecomputer $o /newName:$n /uD:sdirc\clarkj8 /passwordD:$p /force /reboot
}
#NewName txtbox
#OldName txtBox
##############################################PLEASE help here
Function AddOldName {
$row = New-Object PSObject
Add-Member -InputObject $row -MemberType NoteProperty -Name "OldName" -Value $OldName.Text
}