Guest User

Untitled

a guest
Oct 27th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. ##################################################
  2. # Conectando
  3. ##################################################
  4.  
  5. $Account = Login-AzureRmAccount -SubscriptionId $SubscriptionId
  6.  
  7. ##################################################
  8. # Criando o usuário
  9. ##################################################
  10.  
  11. Connect-AzureAD -TenantId $Account.Context.Tenant.Id
  12.  
  13. $Domain = Get-AzureADDomain
  14.  
  15. $AutomationUserEmail = "$($AutomationUserName)@$($Domain.Name)"
  16.  
  17. $PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile
  18. $PasswordProfile.Password = $AutomationUserSenha
  19. $PasswordProfile.EnforceChangePasswordPolicy = $false
  20. $PasswordProfile.ForceChangePasswordNextLogin = $false
  21.  
  22. $AutomationUser = New-AzureADUser -DisplayName $AutomationUserName -PasswordProfile $PasswordProfile -UserPrincipalName $AutomationUserEmail -AccountEnabled $true -MailNickName $AutomationUserName
  23.  
  24. #Aplicando perfil de acesso
  25.  
  26. $RoleId = Get-AzureADDirectoryRole | where { $_.DisplayName -ieq "Cloud Application Administrator" }[0]
  27.  
  28. if($RoleId -eq $null){
  29. $RoleTemplateId = Get-AzureADDirectoryRoleTemplate | where { $_.DisplayName -ieq "Cloud Application Administrator" }[0]
  30. $RoleId = Enable-AzureADDirectoryRole -RoleTemplateId $RoleTemplateId.ObjectId
  31. }
  32.  
  33. Add-AzureADDirectoryRoleMember -ObjectId $RoleId.ObjectId -RefObjectId $AutomationUser.ObjectId
  34.  
  35. #Access control (IAM)
  36. New-AzureRmRoleAssignment -SignInName $AutomationUserEmail -RoleDefinitionName Owner
Add Comment
Please, Sign In to add comment