Error running PowerShell Command from Python Subprocess

24 Views Asked by At

When I try to run following python PowerShell command:

p1 = subprocess.run(
    ['powershell',
     '-Command',
     'Add-DistributionGroupMember -identity "Staff" -member "eng.hassan"'],
    capture_output=True)

I got following error:

'Add-DistributionGroupMember' is not recognized as an internal or external command, operable program or batch file.

Other PowerShell commands executed successfully like (Get-ADUser), I think the error cause this command is part of Exchange Online module not the Active Directory commands.

0

There are 0 best solutions below