首页 > 解决方案 > 在 Python 中创建 auth Powershell auth 对象的最佳方法是什么?

问题描述

我需要从 python 调用 powerCLI。我对 PowerShell 相当陌生,不确定通过创建 System.Management.Automation.PSCredential 对象进行身份验证的最佳方法。在 Python 中创建 powershell auth 对象的最佳方法是什么,这样我最终不会暴露凭据?

这是我正在运行的代码

import asyncio

command = [
    "/usr/local/bin/pwsh",
    "-Command",
    "Connect-VIServer -Server server.name -user 'user' -password 'p@ss' && <command I need to run>",
]

proc = await asyncio.create_subprocess_exec(
    *command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)

stdout, stderr = await await proc.communicate()

标签: pythonpowershellpowercli

解决方案


推荐阅读