Skip to content

Instantly share code, notes, and snippets.

@dfinke
Created October 12, 2023 15:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfinke/c15a9cab41d61152d8e20afac08f8851 to your computer and use it in GitHub Desktop.
Save dfinke/c15a9cab41d61152d8e20afac08f8851 to your computer and use it in GitHub Desktop.
Used GPT4 Vision to take my sketch and create a WPF PS script
# Load necessary .NET libraries
Add-Type -AssemblyName PresentationFramework, WindowsBase
# XAML definition
[xml]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Posh Runner" Height="300" Width="400">
<Grid>
<Label Content="PS Cmd:" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
<TextBox Name="PSCmdTextBox" HorizontalAlignment="Left" Margin="70,10,0,0" VerticalAlignment="Top" Width="250"/>
<Button Content="RUN" HorizontalAlignment="Right" Margin="0,10,10,0" VerticalAlignment="Top" Width="60" Name="RunButton"/>
<DataGrid Name="ResultDataGrid" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,50,10,10">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="*"/>
<DataGridTextColumn Header="Status" Binding="{Binding Status}" Width="*"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
"@
# Read the XAML content and create a WPF window
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$window = [Windows.Markup.XamlReader]::Load($reader)
# Get references to the controls
$runButton = $window.FindName("RunButton")
$psCmdTextBox = $window.FindName("PSCmdTextBox")
$resultDataGrid = $window.FindName("ResultDataGrid")
# Button click event
$runButton.Add_Click({
$command = $psCmdTextBox.Text
if (-not [string]::IsNullOrEmpty($command)) {
try {
$results = Invoke-Expression $command
$resultDataGrid.ItemsSource = $results
}
catch {
[System.Windows.MessageBox]::Show("Error executing command: $_", "Error", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
}
}
})
# Show the WPF window
$window.ShowDialog()
@dfinke
Copy link
Author

dfinke commented Oct 12, 2023

PS-Simple-WPF-Screen

@stahler
Copy link

stahler commented Oct 12, 2023

OMG!

@Blindpete
Copy link

Very Nice 👍👍🕺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment