Hi, I have a PS script that runs every time I trigger PS. The script does import Azure.psd1 as follows
$modulePath = "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1" Import-Module $modulePath
which used to work fine for more than 2 years, so I can issue commands against azure without the need to do import module manually each time1 or 2 years back.
All of a sudden, since a couple of days, whenever I trigger PS, I get an error
Import-Module : The specified module 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1' was not loaded because no valid module file was found in any module directory. At E:\.........\WindowsScripts\PS\PowershellCustomScripts\SetAZureSubscription.ps1:4 char:5 + Import-Module $modulePath + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (C:\Program File...zure\Azure.psd1:String) [Import-Module], FileNotFoundException + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
I was very astonished and visited the directoy, my astonishment was bigger when I discovered that really it was not there, SDK disappeared.
Anyway, I searched MS to reinstall the sdk, I land on a page
where there are sdks for Java, .net but not powershell!!!
I noticed that it was possible to install a module “Azure Powershell”, which I did but when I tried to run the 1st command as follows,
Connect-AzAccount : The ‘Connect-AzAccount’ command was found in the module ‘Az.Accounts’, but the module could not be loaded.
For more information, run 'Import-Module Az.Accounts
At line:1 char:1
- CategoryInfo : ObjectNotFound: (Connect-AzAccount:String) , CommandNotFoundException
- FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
What I understood since V3 of PS that as soon as modules are found in the path in one of the paths inside the variable
when module is called it is automatically loaded, in fact all AZ modules are in
C:\Program Files\WindowsPowerShell\Modules (there are a lot of them)
Any idea what went wrong? why SDK disappeared by itself? wher can I get it?
2nd, how can I load all modules automatically that are found in this directory? Thansks in advance