question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PowerShell unable to load Az.Resources module

See original GitHub issue

System Details

  • macOS Catalina 10.15.1
  • VSCode version 1.41.0-insider
  • PowerShell extension version ms-vscode.powershell-preview 2019.11.0

System Details Output

### PSES version: 2.0.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Darwin 19.0.0 Darwin Kernel Version 19.0.0: Thu Oct 17 16:17:15 PDT 2019; root:xnu-6153.41.3~29/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Description

I am trying to run a PowerShell script that uses the Az.Resources module to export info from Azure AD. This script has worked in the past, and I believe the problems started after I upgraded to macOS Catalina.

I’ve pasted in the script below and also the output.

Script:

# this exports users from Azure AD into a csv file format specified by Tableau for importing users into Tableau Server
# created by chip@montage.co.nz
# last modified 2019-10-16

# retrieve the object id for the nelson Office Azure AD security group
Get-AzADGroup -DisplayName "Nelson Office"

# retrieve all users belonging to the NO security group
$users = Get-AzADGroupMember -GroupObjectId "0bbfc2a1-e862-49f9-9745-c3d82a62cd5b"

# create custom objects for each user with the properties required by Tableau Server for importing users
$userArray = @()
foreach ($user in $users) {
    $properties = @{'UserName' = $user.UserPrincipalName;
                    'Password' = 'password'
                    'DisplayName' = $user.DisplayName;
                    'LicenseLevel' = '';
                    'AdminitratorLevel' = '';
                    'PublishingCapability' = '';
                    'Email' = $user.UserPrincipalName}
    $userArray += New-Object –TypeName PSObject –Prop $properties
}

# output to csv
$userArray | Select-Object -Property UserName, Password, DisplayName, LicenseLevel, AdminitratorLevel, PublishingCapability, Email | 
    ConvertTo-Csv | Set-Content -Path ./azure-ad-users.csv 

# strip out text qualifiers from the csv and also the header row and re-save file
(Get-Content -Path ./azure-ad-users.csv).Replace('"','') | Select-Object -Skip 1 | Set-Content -Path ./azure-ad-users.csv

# display results
Get-Content -Path ./azure-ad-users.csv#### Expected Behaviour

Output:

PowerShell Integrated Console

PS /Users/chip/Dropbox/Code/Powershell> Unable to find type [Microsoft.PowerShell.PSConsoleReadLine].
At line:1 char:71
+ ... :RunClassConstructor([Microsoft.PowerShell.PSConsoleReadLine].TypeHan ...
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Microsoft.PowerShell.PSConsoleReadLine:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
 
PS /Users/chip/Dropbox/Code/Powershell> /Users/chip/Dropbox/Code/Powershell/export-azure-ad-users.ps1

Get-AzADGroup : The 'Get-AzADGroup' command was found in the module 'Az.Resources', but the module could not be loaded. For more information, run 'Import-Module Az.Resources'.
At /Users/chip/Dropbox/Code/Powershell/export-azure-ad-users.ps1:6 char:1
+ Get-AzADGroup -DisplayName "Nelson Office"
+ ~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Get-AzADGroup:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
 
Get-AzADGroupMember : The 'Get-AzADGroupMember' command was found in the module 'Az.Resources', but the module could not be loaded. For more information, run 'Import-Module Az.Resources'.
At /Users/chip/Dropbox/Code/Powershell/export-azure-ad-users.ps1:9 char:10
+ $users = Get-AzADGroupMember -GroupObjectId "0bbfc2a1-e862-49f9-9745- ...
+          ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Get-AzADGroupMember:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
 
krupesh.desai@montage.co.nz,password,Krupesh Desai,,,,krupesh.desai@montage.co.nz
PS> ./export-azure-ad-users.ps1
Get-AzADGroup : The 'Get-AzADGroup' command was found in the module 'Az.Resources', but the module could not be loaded. For more information, run 'Import-Module Az.Resources'.
At /Users/chip/Dropbox/Code/Powershell/export-azure-ad-users.ps1:6 char:1
+ Get-AzADGroup -DisplayName "Nelson Office"
+ ~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Get-AzADGroup:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
 
Get-AzADGroupMember : The 'Get-AzADGroupMember' command was found in the module 'Az.Resources', but the module could not be loaded. For more information, run 'Import-Module Az.Resources'.
At /Users/chip/Dropbox/Code/Powershell/export-azure-ad-users.ps1:9 char:10
+ $users = Get-AzADGroupMember -GroupObjectId "0bbfc2a1-e862-49f9-9745- ...
+          ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Get-AzADGroupMember:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
 
krupesh.desai@montage.co.nz,password,Krupesh Desai,,,,krupesh.desai@montage.co.nz
ersion: $($pseditor.EditorServicesVersion)"; "`n### PowerShell version:`n$($PSVersionTable | Out-String)"}ions:`n$(code-insiders --list-extensions --show-versions | Out-String)"; "`n### PSES v
code-insiders : The term 'code-insiders' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:27
+ & {"### VSCode version: $(code-insiders -v)"; "`n### VSCode extension ...
+                           ~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (code-insiders:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException 

### VSCode version: 
code-insiders : The term 'code-insiders' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:76
+ ... ode-insiders -v)"; "`n### VSCode extensions:`n$(code-insiders --list- ...
+                                                     ~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (code-insiders:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

VSCode extensions:

PSES version: 2.0.0.0

PowerShell version:

Name Value


PSVersion 6.2.3 PSEdition Core GitCommitId 6.2.3 OS Darwin 19.0.0 Darwin Kernel Version 19.0.0: Thu Oct 17 16:17:15 PDT 2019; root:xnu-6153.41.3~29/RELEASE_X86_64 Platform Unix PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

PS /Users/chip/Dropbox/Code/Powershell> Unable to find type [Microsoft.PowerShell.PSConsoleReadLine]. At line:1 char:71

  • … :RunClassConstructor([Microsoft.PowerShell.PSConsoleReadLine].TypeHan …
  •                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  • CategoryInfo : InvalidOperation: (Microsoft.PowerShell.PSConsoleReadLine:TypeName) [], RuntimeException
  • FullyQualifiedErrorId : TypeNotFound

PS /Users/chip/Dropbox/Code/Powershell> /Users/chip/Dropbox/Code/Powershell/export-azure-ad-users.ps1

Get-AzADGroup : The ‘Get-AzADGroup’ command was found in the module ‘Az.Resources’, but the module could not be loaded. For more information, run ‘Import-Module Az.Resources’. At /Users/chip/Dropbox/Code/Powershell/export-azure-ad-users.ps1:6 char:1

  • Get-AzADGroup -DisplayName “Nelson Office”
  • CategoryInfo : ObjectNotFound: (Get-AzADGroup:String) [], CommandNotFoundException
  • FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Get-AzADGroupMember : The ‘Get-AzADGroupMember’ command was found in the module ‘Az.Resources’, but the module could not be loaded. For more information, run ‘Import-Module Az.Resources’. At /Users/chip/Dropbox/Code/Powershell/export-azure-ad-users.ps1:9 char:10

  • $users = Get-AzADGroupMember -GroupObjectId "0bbfc2a1-e862-49f9-9745- …
  •      ~~~~~~~~~~~~~~~~~~~
    
  • CategoryInfo : ObjectNotFound: (Get-AzADGroupMember:String) [], CommandNotFoundException
  • FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Attached Logs

I’ve attached the powershell and editor services logs: Archive.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
chip-felton-montagecommented, Nov 29, 2019

I am seeing one issue with your fix though. When the Powershell integrated console starts up in Visual Studio, I get the error below:


=== PowerShell Integrated Console ===
PS /Users/chip/Dropbox/Code/Powershell>

An error occurred while reading input:

System.TypeInitializationException: The type initializer for 'UnixConsoleEcho.InputEcho' threw an exception. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Runtime.InteropServices.OSPlatform.get_Windows()
   at UnixConsoleEcho.InputEcho..cctor()
   --- End of inner exception stack trace ---
   at UnixConsoleEcho.InputEcho.Disable()
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContext.UnixConsoleOperations.ReadKeyAsync(Boolean intercept, CancellationToken cancellationToken) in C:\Users\Robert Holt\Documents\Dev\Microsoft\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShellContext\Console\UnixConsoleOperations.cs:line 94
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContext.ConsoleReadLine.ReadKeyAsync(CancellationToken cancellationToken) in C:\Users\Robert Holt\Documents\Dev\Microsoft\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShellContext\Console\ConsoleReadLine.cs:line 132
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContext.ConsoleReadLine.InvokeLegacyReadLineAsync(Boolean isCommandLine, CancellationToken cancellationToken) in C:\Users\Robert Holt\Documents\Dev\Microsoft\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShellContext\Console\ConsoleReadLine.cs:line 180
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContext.LegacyReadLineContext.InvokeReadLineAsync(Boolean isCommandLine, CancellationToken cancellationToken) in C:\Users\Robert Holt\Documents\Dev\Microsoft\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShellContext\Session\LegacyReadLineContext.cs:line 27
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContextService.InvokeReadLineAsync(Boolean isCommandLine, CancellationToken cancellationToken) in C:\Users\Robert Holt\Documents\Dev\Microsoft\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShellContext\PowerShellContextService.cs:line 1117
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContext.ConsoleReadLine.ReadLineAsync(Boolean isCommandLine, CancellationToken cancellationToken) in C:\Users\Robert Holt\Documents\Dev\Microsoft\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShellContext\Console\ConsoleReadLine.cs:line 137
   at Microsoft.PowerShell.EditorServices.Services.PowerShellContext.EditorServicesPSHostUserInterface.StartReplLoopAsync(CancellationToken cancellationToken) in C:\Users\Robert Holt\Documents\Dev\Microsoft\PowerShellEditorServices\src\PowerShellEditorServices\Services\PowerShellContext\Session\Host\EditorServicesPSHostUserInterface.cs:line 829

PS /Users/chip/Dropbox/Code/Powershell>

0reactions
msftbot[bot]commented, Dec 1, 2019

This issue has been marked as duplicate and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting the Azure Az PowerShell module
This message occurs when you have both the Az and AzureRM PowerShell modules installed on the same Windows-based system and they exist in...
Read more >
azure-powershell/troubleshoot-module-load.md at main - GitHub
Symptom: Cannot load Az modules in Windows PowerShell. The Az modules are built against .NET Standard. This will cause them to fail in...
Read more >
Unable to use new Az module in Azure Devops
Hi, you can try to use Azure PowerShell Version 4 of the task in order to work with Az module.. Click to vote...
Read more >
Why can't PowerShell load file or assembly to run Azure ...
Can you provide the versions of . · Also, are you running both the new Az as well as the old AzureRM PowerShell...
Read more >
The specified module 'Module Name' was not loaded because ...
This error is because the PowerShell console or ISE is unable to get the module from given module path's in the environment variable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found