How can I get a PowerShell script to read and store output from an executable?

0
7
Asked By CuriousCoder42 On

I'm trying to create a PowerShell script that runs an executable (provided by a colleague) to read the Windows Edition from the MSDM table in the BIOS. The application outputs multiple lines, but I specifically need to know if the version is Home or Pro. After determining the version, I want to save it as a variable in a task sequence (specifically for MDT, although I'm curious if this works differently in SCCM). I'm still learning PowerShell, so I appreciate any help with my script. Here's what I have so far: I set up the directory, load the Task Sequence environment, execute the executable, and try to process the output. However, I'm not sure if it's working correctly. Any suggestions on how to improve this?

2 Answers

Answered By TechWhiz123 On

It sounds like your executable might not be outputting properly to the console. You could try redirecting the output stream to capture it. There's a guide on redirection in PowerShell that could be really useful. Alternatively, you could get the information using a native PowerShell command like `Get-CimInstance -ClassName SoftwareLicensingService | Select OA3xOriginalProductKey` instead of relying on the executable. This might simplify things!

ScripterGal -

That's a great idea! OP might also consider checking the OS version with CIM using the command `Get-CimInstance -ClassName Win32_OperatingSystem | Select Caption` if they want to bypass the executable entirely.

Answered By ScriptSquad On

What exactly isn't working with your script? It seems like something might be causing it to fail in the task sequence. Since the PowerShell window is hidden during execution in MDT, debugging can be tricky, but checking the logs might help pinpoint the issue.

CodemasterX -

The task sequence fails after running the script, but it's hard to see why since the PowerShell window is tucked away. Looking at the stage it fails at might give clues—maybe there's an issue with how you’re capturing or processing the output.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.