Private/aad.ps1
function Get-RKAADServicePrincipalObjectId { [CmdletBinding()] param([string]$ApplicationName) $ApplicationId = (Get-AzADApplication -DisplayName $ApplicationName).ApplicationId if (!($ApplicationId)) { throw "Application $ApplicationName not found" } return (Get-AzADServicePrincipal -ApplicationId $ApplicationId).Id } function Get-RKAADGroupObjectId { [CmdletBinding()] param([string]$GroupName) $Id = (Get-AzAdGroup -DisplayName $GroupName).Id if (!($Id)) { throw "AAD Group $GroupName not found" } return $Id } function Get-RKAADUserObjectId { [CmdletBinding()] param([string]$UserName) $Id = (Get-AzAdUser -UserPrincipalName $UserName).Id if (!($Id)) { throw "AAD User $UserName not found" } return $Id } function Get-RKResourceMSI { [CmdletBinding()] param([string]$ResourceId) # Assign stdout to $null as its clogging up the pipeline. $Null = @( # Redirect stderr to $null as we want to control the error elsewhere. ( $App = Get-AzResource -ResourceId $ResourceId ) 2> $null if (!($App)) { throw "Resource MSI $ResourceId not found" } ) return $App.Identity.PrincipalId } |