首页 > 解决方案 > 脚本从 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

标签: powershellpowerclipowershell-ise

解决方案


尝试在提升级别运行 powershell 命令 shell。从提升的 powershell 命令外壳运行您的脚本。shift + 鼠标右键单击 powershell 图标并选择以管理员身份运行,一旦打开运行您的脚本。


推荐阅读