powershell - 脚本从 powershell ISE 工作,但不是从 powershell
问题描述
我正在尝试使用 powercli 连接到 vsphere,powershell 脚本内容如下,
# test.ps1
Set-PowerCLIConfiguration -Scope User -InvalidCertificateAction Ignore -Confirm:$False
Connect-VIServer server_name -User username -Password pass
如果我从 powershell ISE 执行脚本,它工作正常并且会连接。但同样的情况并没有从 powershell 发生并且低于错误
Connect-VIServer : 8/11/2021 4:00:32 PM Connect-VIServer Error: Invalid server certificate. Use
Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you'd like to connect
once or to add a permanent exception for this server.
Additional Information: Could not establish secure channel for SSL/TLS with authority 'x.x.x.x'.
At line:1 char:1
+ Connect-VIServer x.x.x.x -User username -Password pass
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [Connect-VIServer], ViSecurityNegotiationException
+ FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_CertificateError,VMware.VimAutomation.ViCore.
Cmdlets.Commands.ConnectVIServer
解决方案
尝试在提升级别运行 powershell 命令 shell。从提升的 powershell 命令外壳运行您的脚本。shift + 鼠标右键单击 powershell 图标并选择以管理员身份运行,一旦打开运行您的脚本。
推荐阅读
- c - Paho MQTT C 客户端库中的错误
- android - 无法设置会话
- javascript - 运行一次后,您可以更改 javascript 函数中的语句吗
- javascript - 带有打字稿的量角器中的下拉菜单
- angular - 如何在角度 4 中路由后显示烤面包机
- apache-spark - spark应用程序中应该有多少最小驱动程序内存?
- javascript - 如何获取事件目标默认值 JavaScript
- angular - 当令牌在角度4中过期时如何重定向到注销
- python - 如何从张量流中的两个二维张量中获取交叉合约矩阵?
- javascript - 如何设置带有撇号和引号的 javascript 变量(无法转义!)