0

I'm trying to store data from the active directory in a variable. When i run this code using python i get nothing:

import subprocess, sys

def run(cmd):
    completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True)
    return completed

command = """$username = 'adminuser'
$password = 'password'
$GivenName = 'John'
$Surname = 'White'

$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword

$test = get-aduser -filter 'GivenName -like $GivenName -and Surname -like $Surname' -Properties Name, officephone, mobilephone, Description -Credential $credential
$rbd = "asdasd"
$test|ConvertTo-Json
"""
info = run(command)
print(info.stdout.decode('utf-8'))
    
print("-------------------------")

However when i run command in powershell or cmd it works fine. Returns Name, officephone, mobilephone and Description info. Why i can't get data using python?

Denzel
  • 359
  • 4
  • 12

0 Answers0