Example Code

Automating the PowerShell Execution with LabVIEW - Example Code

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

    Other

  • Powershell

Code and Documents

Attachment

Description

This example shows how LabVIEW can:

  1. Launch powershell.exe.
  2. Bring the PowerShell window to the foreground using IWshShell.AppActivate.
  3. Send commands using IWshShell.SendKeys.
  4. Execute those commands interactively in the PowerShell console.

It is a straightforward way to integrate PowerShell commands into LabVIEW, but for robust automation, redirecting Standard Input/Output is generally preferable because it removes the dependency on window focus and allows LabVIEW to directly capture command results.

 

Note: The VIs are built using LabVIEW 2026 Q1.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors