Thanks for your responses. I modified the code to specify powershell7 and got the correct output.
def get_powershell_table(command):
"""Executes a PowerShell command and returns the formatted table output as a string."""
try:
result = subprocess.run(
[r"C:\Program Files\PowerShell\7\pwsh.exe", "-Command", command],
capture_output=True,
text=True,
check=True,
)
return result.stdout
except subprocess.CalledProcessError as e:
print(f"Error executing PowerShell command: {e}")
return None