I have to execute the PS script on one of the APIs in my .Net Core application. Previously I used AzureRm commands in my PS script with the .Net framework. But after upgrading to .Net Core this script stopped working. Then I updated the PS script to use Az commands then it gave me an error :
"The specified module 'Az' was not loaded because no valid module file was found in any module directory."
DevOps Powershell Script to install Az module:
Install-Module -Name Az -RequiredVersion 2.8.0 -Force -AllowClobber
Get-InstalledModule #Just print out the details to confirm whether `Az 2.8.0` has been installed successfully
// Even setting PSModulePath is not working
$key = (Get-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager').OpenSubKey('Environment', $true)
$path = $key.GetValue('PSModulePath','','DoNotExpandEnvironmentNames')
$path += ';D:\Program Files (x86)\ManagedDependencies\PowerShell\AzPSModules\1.0.0'
$key.SetValue('PSModulePath',$path,[Microsoft.Win32.RegistryValueKind]::ExpandString)
What should I do to execute the Az command in the PS script?