-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get-AzRoleDefinition : Object reference not set to an instance of an object. #22716
Comments
Thanks for reporting :) @NoriZC hi, please go through the issue and let's talk about it. Thanks. |
Hi @terrycms, Could you please run |
Also please make sure to mask any sensitive information before posting it here. |
PS C:\WINDOWS\system32> Get-AzContext Tried connect-azuread and Add-AzureAccount before and after Get-AzContext, but get same result as shown above |
Reopen this because we rolled back the fix. #22866 |
When is this going to be fixed? |
@Dylan-Prins This should be already fixed. Could you please install the latest Resources module and have a try? |
I can confirm this is fixed. |
Hi @Dylan-Prins , You can choose a specific Azure PowerShell version in Azure Pipelines. |
For people still coming across this issue, even in the latest preview release, the Object reference error is also thrown if you forget to run |
Description
Attempting to find the name of an Azure AD built-in role. Getting errors in powershell. I suspect there is an issue between Az and Rm modules but not sure how to resolve it.
The bug not just that Get-AzRoleDefinition doesn't work; it is mostly a bug about user experience for the Az modules; see the attempts below to get role definitions from AzureAd. The Az module can be improved to let me know what to do to resolve the issue or resolve the problem for me.
C:\WINDOWS\system32> Get-AzRoleDefinition | FT Name, Description Get-AzRoleDefinition : The term 'Get-AzRoleDefinition' 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:1 + Get-AzRoleDefinition | FT Name, Description + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-AzRoleDefinition:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\WINDOWS\system32> Import-Module Az.Accounts Install-Module Import-Module : A positional parameter cannot be found that accepts argument 'Install-Module'. At line:1 char:1 + Import-Module Az.Accounts Install-Module + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Import-Module], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
PS C:\WINDOWS\system32> Install-Module -Name Az -Repository PSGallery -Force
PackageManagement\Install-Package : The following commands are already available on this
system:'Login-AzAccount,Logout-AzAccount,Resolve-Error,Send-Feedback'. This module 'Az.Accounts' may override the
existing commands. If you still want to install this module 'Az.Accounts', use -AllowClobber parameter.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
Exception
ageManagement.Cmdlets.InstallPackage
PS C:\WINDOWS\system32> PS C:\WINDOWS\system32> Install-Module -Name Az -Repository PSGallery -Force -AllowClobber PS C:\WINDOWS\system32> Get-AzRoleDefinition | FT Name, Description WARNING: Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide Get-AzRoleDefinition : Object reference not set to an instance of an object. At line:1 char:1 + Get-AzRoleDefinition | FT Name, Description
PS C:\WINDOWS\system32> Uninstall-AzureRm
PS C:\WINDOWS\system32> Get-AzRoleDefinition | FT Name, Description
Get-AzRoleDefinition : Object reference not set to an instance of an object.
At line:1 char:1
PS C:\WINDOWS\system32> Get-AzRoleDefinition
Get-AzRoleDefinition : Object reference not set to an instance of an object.
At line:1 char:1
PS C:\WINDOWS\system32> Install-Module -Name Az -Repository PSGallery -Force -AllowClobber
WARNING: The version '2.12.5' of module 'Az.Accounts' is currently in use. Retry the operation after closing the
applications.
WARNING: The version '6.9.0' of module 'Az.Resources' is currently in use. Retry the operation after closing the
applications.
PS C:\WINDOWS\system32> Get-AzRoleDefinition
Get-AzRoleDefinition : Object reference not set to an instance of an object.
At line:1 char:1
PS C:\WINDOWS\system32> Get-AzRoleDefinition
Get-AzRoleDefinition : Object reference not set to an instance of an object.
At line:1 char:1
PS C:\WINDOWS\system32> Get-AzRoleDefinition -Id 13bd1c72-6f4a-4dcf-985f-18d3b80f208a
Get-AzRoleDefinition : Object reference not set to an instance of an object.
At line:1 char:2
PS C:\WINDOWS\system32> Get-AzRoleDefinition -Id 13bd1c72-6f4a-4dcf-985f-18d3b80f208a
Get-AzRoleDefinition : Object reference not set to an instance of an object.
At line:1 char:2
PS C:\WINDOWS\system32> Get-AzRoleDefinition
Get-AzRoleDefinition : Object reference not set to an instance of an object.
At line:1 char:1
Issue script & Debug output
Environment data
Module versions
Error output
The text was updated successfully, but these errors were encountered: