Public/Set-FMTFlexVnetRole.ps1
function Set-FMTFlexVnetRole { param( [parameter(Mandatory)] [string] $flexRG, [parameter(Mandatory)] [string] $flexVM, [parameter(Mandatory)] [string] $vnet, [parameter(Mandatory)] [string] $vnetRG, [parameter(Mandatory)] [string] $role ) $flexVMObj = Get-AzVM -Name $flexVM -ResourceGroupName $flexRG $flexrole = Get-AzRoleDefinition -Name $role $flexVnet = Get-AzVirtualNetwork -Name $vnet -ResourceGroupName $vnetRG New-AzRoleAssignment -ObjectId $flexVMObj.Identity.PrincipalId -RoleDefinitionName $flexrole.name -scope $flexVnet.id } |