this post was submitted on 07 Jun 2024
446 points (91.0% liked)

Programmer Humor

32410 readers
253 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

Since people are curious Ill explain why:

I need to build our project from the remote repo using a PowerShell script (.ps1). I’m using Bash in the VSCode terminal, I have to run the .ps1 script in a new Command Prompt because the compilation takes around 5 minutes and I need my terminal for other things. To do this, the only way is to run a batch file that executes the .ps1 script.

Its an automation so I dont need to touch powershell whatsover and remain in bash terminal. Instead of opening several windows, I automated all so it only takes 1 alias to compile my shit.

The compilation also requires several inputs and "Key Presses", so I automated all of that in the Batch file.

you are viewing a single comment's thread
view the rest of the comments
[–] tux7350@lemmy.world 1 points 5 months ago (1 children)

I can create tools for my company that launches right out of ConfigMgr Software Center and other technicians can contribute without needing a programming background.

Now this is a bit of magic I would like to learn. I read through PowerShell in a month of lunches a couple of years ago and it's saved my butt a couple of times. I'm due for a re-read though. Would you have a source on where I could go to learn more about creating GUI applications in PowerShell?

[–] discusseded@programming.dev 2 points 5 months ago* (last edited 5 months ago)

This blog does a fairly straight-forward job on explaining the basics. For me, I learn best in an interactive 1:1 or well-constructed video, so ChatGPT was priceless. I could ask it stupid questions all day long, and after throwing some different ideas around I started to see the essential parts and just let my prior knowledge of PS, .NET, and C# WPF take it from there.

At the end of the day, all that really matters is using the PresentationFramework assembly and creating a window:

  • Add-Type -AssemblyName PresentationFramework
  • Either use Visual Studio > WPF Project and make the UI you want. Take the XAML file and use PowerShell to get the raw content:
    • $Xaml = Get-Content -Path MainWindow.xaml -Raw
    • $SanitizedXaml = $Xaml -replace "bad syntax e.g. Foreground={x:Null}" "Foreground="Transparent" # Certain XAML syntax is incompatible with PS XML
    • [xml]$XmlReader = [System.Xml.XmlNodeReader]::new($SanitizedXaml)
    • $Window = [Windows.Markup.XamlReader]::Load($XmlReader)
  • Or, use .NET-style syntax in PS directly:
  • Then show the window:
    • $Window.ShowDialog() | Out-Null