[Python] Execute Powershell Command remotely and print the output using wmi python

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    I want to execute powershell command remotely and fetch the output. The command is "(New-Object -c Microsoft.Update.Session).CreateUpdateSearcher().Search("IsInstalled=0").Updates|Select Title".
    I have tried

    import wmi
    try:
    connection = wmi.WMI(ip, user=username, password=password)
    print("connection is established")
    connection.Win32_Process.Create(CommandLine='powershell.exe /c (New-Object -c Microsoft.Update.Session).CreateUpdateSearcher().Search("IsInstalled=0").Updates|Select Title > C:\output.txt')
    except:
    print("connection failed")

    Continue reading...

Compartilhe esta Página