简体   繁体   English

如何从Visual Studio Code Terminal连接到Azure

[英]How to Connect to Azure from Visual Studio Code Terminal

I have installed the required software and Azure PowerShell cmdlets on local system. 我已经在本地系统上安装了必需的软件和Azure PowerShell cmdlet。 I tried to execute a powershell script by connecting to Azure from Visual Studio Code Terminal. 我试图通过从Visual Studio Code Terminal连接到Azure来执行Powershell脚本。 Below is the error. 下面是错误。

Import-Module Microsoft.Online.SharePoint.PowerShell 

function PublishToAzure{ 
 Add-AzureAccount
......
......
}

Error is.. Add-AzureAccount : The handle is invalid 错误是.. Add-AzureAccount:句柄无效

Visual Studio Code Settings: Visual Studio代码设置:

// Place your settings in this file to overwrite the default settings
{  
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
}

Console of Windows Azure Active Directory Module for Windows PowerShell Properties Target is: 用于Windows PowerShell属性目标的Windows Azure Active Directory模块的控制台是:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command "Import-Module MSOnline"

System Properties: 64bit Win7 OS 系统属性:64位Win7 OS

You may connect and manage Azure resources from within VS Code's terminal window by installing Microsoft Azure CLI 2.0. 您可以通过安装Microsoft Azure CLI 2.0在VS Code的终端窗口中连接和管理Azure资源。 ( https://aka.ms/InstallAzureCliWindows ). https://aka.ms/InstallAzureCliWindows )。

After CLI 2.0 is successfully installed in your environment, add the CLI 2.0 components to your environment path. 在您的环境中成功安装CLI 2.0之后,请将CLI 2.0组件添加到您的环境路径中。

For example, my environment is Windows 10 and VS Code v1.13.0. 例如,我的环境是Windows 10和VS Code v1.13.0。 I successfully ran the CLI 2.0 MSI installer for Windows. 我已成功运行Windows的CLI 2.0 MSI安装程序。 In my VS Code terminal session, I add the path to my PowerShell environment via this command: 在我的VS Code终端会话中,我通过以下命令将路径添加到PowerShell环境:

$Env:Path += ';C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin'

To work within my Azure subscription(s), first I login via the command 要在我的Azure订阅中工作,首先我通过命令登录

az login

Follow the prompts to browse to a URL to complete the login to your Azure account and authorize the CLI session. 按照提示浏览至URL,以完成对Azure帐户的登录并授权CLI会话。 Additional help on CLI 2.0 commands may be found at this link, https://aka.ms/cli 可以在以下链接中找到有关CLI 2.0命令的其他帮助:https://aka.ms/cli

I know this thread is old and my answer a bit late but I hope this helps someone. 我知道这个主题很旧,我的回答有点晚了,但是我希望这对某人有帮助。

Cheers, CarnegieJ 卡内基,干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM