简体   繁体   中英

How to Connect to Azure from Visual Studio Code Terminal

I have installed the required software and Azure PowerShell cmdlets on local system. I tried to execute a powershell script by connecting to Azure from Visual Studio Code Terminal. Below is the error.

Import-Module Microsoft.Online.SharePoint.PowerShell 

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

Error is.. Add-AzureAccount : The handle is invalid

Visual Studio Code Settings:

// 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:

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

System Properties: 64bit Win7 OS

You may connect and manage Azure resources from within VS Code's terminal window by installing Microsoft Azure CLI 2.0. ( https://aka.ms/InstallAzureCliWindows ).

After CLI 2.0 is successfully installed in your environment, add the CLI 2.0 components to your environment path.

For example, my environment is Windows 10 and VS Code v1.13.0. I successfully ran the CLI 2.0 MSI installer for Windows. In my VS Code terminal session, I add the path to my PowerShell environment via this command:

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

To work within my Azure subscription(s), first I login via the command

az login

Follow the prompts to browse to a URL to complete the login to your Azure account and authorize the CLI session. Additional help on CLI 2.0 commands may be found at this link, https://aka.ms/cli

I know this thread is old and my answer a bit late but I hope this helps someone.

Cheers, CarnegieJ

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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