"Connect-MsGraph' is not recognized as the name of a cmdlet - azure

I have a couple of PowerShell scripts that can run using Windows PowerShell with no issue.
As soon as I run them in VS Code on the same computer, I get "Connect-MsGraph' is not recognized as the name of a cmdlet,
I have installed the same Microsoft.Graph.Intune and other relevant AAD modules for both Windows PowerShell and VS Code.
Any idea why I can't run them in the VS Code?
Thanks

Connect-MsGraph' is not recognized as the name of a cmdlet,
The issue happens because of the VS code is not able to access the PSModulePath in the system or it happens if you are not using the latest Microsoft.Graph SDK.
Try to install the module in a default path
Install-Module -Name Microsoft.Graph -RequiredVersion 1.2.0
Refer here if in your system default path contains OneDrive.
After adding the required modules in a default path try to restart the VS Code and System.
References
Connect MS Graph in VS Code

Related

Trouble finding the GAC file needed to run an assembly in powershell

I am using PowerShell for some work in Azure. I am trying to run this code, but I get an error saying:
'Unable to find type [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider].'
$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext
I tried everything to fix it I searched for the DLL file I need, but to no avail. I tried to add the type using this command:
add-type -assemblyname Microsoft.Azure.Common
But that also gives an error. I am also using the latest version of PowerShell:
Name
Value
PSVersion
5.1.18362.1171
PSEdition
Desktop
PSCompatibleVersions
{1.0, 2.0, 3.0, 4.0...}
BuildVersion
10.0.18362.1171
CLRVersion
4.0.30319.42000
WSManStackVersion
3.0
PSRemotingProtocolVersion
2.3
SerializationVersion
1.1.0.1
Please help!
The error was caused because it was using Azure CLI. If Azure powershell is used it causes no error. They are different.
I am not sure if you have solved this issue, but you should have some misunderstandings about them, if you run this line in the PowerShell locally, this issue has nothing to do with Azure CLI, Azure CLI is another type of command written by python.
To solve the issue, you just need to import the module Az.Accounts via Import-Module -Name Az.Accounts -Force, make sure you have installed Az powershell module first, then login with Connect-AzAccount, normally it will import the Az.Accounts module automatically meanwhile for you, no need to do it manually. So if you find it works fine now without import anything, actually it imports it for you automatically.
Sample:
Connect-AzAccount
$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext
Manual way:

Cloudn't register-PSRepository in my Windows10 for installing Azure PowerShell

I want to install Azure PowerShell in my windows 10, but I met an error message, I tried to find the reason for the error and found there was no package when I ran Get-PSRepository.
Background:
Install azure with code as below:
Install-Module -Name Az -AllowClobber -Scope AllUsers
Install-Module -Name Az -Repository PSGallery -Force
Error message:
Can't find the package at C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1748
Register-PSRepository -Default
Get-PSRepository shows can't find the package.
net winhttp show proxy shows without proxy server
what should I do to install the azure PowerShell?
Based on your error message, it seems that you have connection issue to powershell gallery
So, my first suggestion is to check your network environment work. Also remember to check your system proxy settings.
If your network has no problem, you may download package manually and then install modules from the downloaded nuget package
Another choice is to use Azure Cloud Shell
Hope the above could be helpful to you!

Azure module installation in Powershell

I am trying to install azure module but it is showing the error
"unable to download the list of available providers, Check your internet connection.
Check your proxy settings and your firewall rule to be sure everything is working fine. If not working, you could download the module to your local computer and import it to the powershell.
Import-Module c:\windows\uyhe.ps1
Ensure the Execution-Policy is RemoteSigned
Set-ExecutionPolicy RemoteSigned
Hope this helps

Install Microsoft Azure CLI without using Microsoft documentation

I am trying to install Azure CLI as described in Microsoft documentation "Install Azure CLI 2.0"1. The documentation seems out-of-date, hard to understand and has many issues associated with it. Each step in the documentation introduces new issues to fix first. An example is shown below.
PS C:\WINDOWS\system32> Install-Module AzureRM
Install-Module : The 'Install-Module' command was found in the module 'PowerShellGet', but the module could not be load
ed. For more information, run 'Import-Module PowerShellGet'.
At line:1 char:1
+ Install-Module AzureRM
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Install-Module:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
PS C:\WINDOWS\system32>
or
PS C:\Users\ostraaten> Import-Module AzureRM
Import-Module : The specified module 'AzureRM' was not loaded because no valid module file was found in any mod
ctory.
At line:1 char:1
+ Import-Module AzureRM
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (AzureRM:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Are there other ways to get Azure CLI? Third-party installers for example. Is there more up-to-date documentation? Better tested documentation?
I cannot use btw the Azure CLI for Linux - which does work - because I need a reserved public static IP address which can only be created using MS Windows CLI for Windows. It also cannot be created through the portal. For reasons unknown.
I also tried the Cloud Shell where CLI is pre-installed but that version is older and doesn't include the method to create reserved IP address. Updating the CLI version in Cloud Shell is also not possible. It fails with an error message.
As a workaround, we can download Azure CLI 2.0 MSI and install it on your Windows PC.
We can download MSI here.
Update:
If you want to install Azure PowerShell, we can download Azure PowerShell MSI here.
More information, please refer to this link.
First of all, there is a difference between the Azure CLI and Azure Powershell.
The command Install-Module AzureRM installs the latter.
AzureCLI adds the az command. If you open a command prompt and just type az, you either see an error or a list of available commands. Note: on Windows 10 you can either install the CLI directly under Windows, or you can install it under the subsystem for linux.
Enabling Ubuntu Bash is described here:
Settings -> Update and Security -> For Developers -> Developer Mode
Control Panel -> Programs -> Windows Features -> Windows Subsystem for Linux
Installing the Azure CLI here is described here:
Azure PowerShell is another way of talking to the Azure REST API. The error you're getting indicates there's something wrong with your PowerShell Repository.
Did you verify Azure really isn't installed? You can test this by trying Login-AzureRmAccount.
If you get an error you may try Register-PSRepository -Default before following the steps here

Add-AzureKeyVaultManagedStorageAccount cmdlet not found in AzureRM.KeyVault v. 3.1.0

According to Powershell Gallery the 3.1.0 version of AzureRM.KeyVault contains cmdlets supporting Azure Storage accounts whose keys are managed by KeyVault. I installed and Get-Module shows the 3.1.0 version, but I am not seeing (in ExportedCommands) the various commands to support storage.
Here are the steps I would do.
Shutdown all powershell processes or reboot
Go to c:\program files\windowspowershell\modules and delete the folder with the AzureRM.keyvault in name
Launch powershell and install the module Install-Module -Name AzureRM.KeyVault

Resources