How to Automate PowerShell Command Execution From LabVIEW

Updated Oct 1, 2026

Environment

Software

  • LabVIEW

Operating System

  • Windows

You can use a LabVIEW VI to automatically launch a Microsoft Windows PowerShell window and continuously send commands to the active PowerShell session. This approach allows you to execute PowerShell commands interactively from LabVIEW while viewing the command output directly in the opened PowerShell window.
 
This method is intended for LabVIEW users who need to automate command-line operations without closing the PowerShell session after each command execution.
 
Prerequisites:
  • NI LabVIEW
  • Microsoft Windows PowerShell
  • ActiveX support enabled in Windows
  • Access to the IWshRuntimeLibrary.IWshShell3 ActiveX interface

  1. Create a new process to launch PowerShell using .NET Process classes.
  2. Configure the process start information:
    1. Set the filename to powershell.exe.
    2. Add any required startup arguments, such as: "-NoProfile -NoExit"
    3. Disable standard input/output redirection if the goal is to display commands and results directly in the PowerShell window.
  1. Start the process using the Process Start method. The following block diagram launches powershell.exe with the arguments -NoProfile -NoExit.

  1. Create an ActiveX Automation Reference using IWshRuntimeLibrary.IWshShell3.
  2. Use the ActiveX AppActivate method to activate the PowerShell window. The ActiveX AppActivate method brings the PowerShell window to the foreground before sending commands.

  1. Insert a brief delay after activation to ensure the PowerShell window receives focus.
  2. Write the desired PowerShell command in a LabVIEW string control.
  3. Use the ActiveX SendKeys method to send the command text to the active PowerShell window. The ActiveX SendKeys method writes the command string to the active PowerShell window.

  1. Append an keystroke to execute the command.
  2. Repeat the command-sending operation as needed to continuously issue PowerShell commands from LabVIEW.
  3. Stop the VI when command execution is complete.

After completing these steps:
  • LabVIEW launches a new PowerShell window.
  • Commands entered from the LabVIEW front panel are automatically typed into the PowerShell session.
  • Command output remains visible in the PowerShell window.
  • Additional commands can be sent without reopening PowerShell.

Example showing the LabVIEW VI sending the Get-Date command to Windows PowerShell and displaying the result in the PowerShell console.
 
Front Panel:
 
 
Block Diagram:
 
 
PowerShell Window:
 

Next Steps

  • Modify the command string control to send dynamic PowerShell commands.Add error handling to detect failed PowerShell launches.
  • Implement command queuing for automated test sequences.
  • Consider using standard input redirection instead of SendKeys for applications that require more reliable command execution.