Public/Set-FMTFlexRGRole.ps1

function Set-FMTFlexRGRole {
    param(
        [parameter(Mandatory)]
        [string] $flexRG,
        [parameter(Mandatory)]
        [string] $flexVM,
        [parameter(Mandatory)]
        [string] $role
    )

        $flexVMObj = Get-AzVM -Name $flexVM -ResourceGroupName $flexRG
        $flexrole = Get-AzRoleDefinition -Name $role  
        $flexRG = Get-AzResourceGroup -ResourceGroupName $flexRG

        New-AzRoleAssignment -ObjectId $flexVMObj.Identity.PrincipalId -RoleDefinitionName $flexrole.name -scope $flexRG.id
}