python - 在 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()
解决方案
推荐阅读
- javascript - 如何将多个 if 语句重构为更简洁的代码?
- json - 使用 JQ 将 json 属性值级联到所有为空的后代
- django - Django 频道获取当前频道
- python - 在 Python 中使用 assert 检查条件是否为 False
- java - 我无法使用 getGraphics() 方法绘制任何东西
- javascript - Safari 从内存缓存中获取图像的时间太长
- spring-integration - Spring Integration:自上次轮询以来仅摄取新文件
- java - 将十进制值转换为二进制时遇到问题
- python - 无法应用一个非常简单的 json.dumps 解决方案,为什么?
- vue.js - Nuxt.js - API 调用的最佳场所