Guest User

Untitled

a guest
Dec 18th, 2017
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. Param (
  2. [string]$msolDisplayName = "SVC-Nework-Gateway-Updater",
  3. [string]$msolFirstName = "Network-Gateway",
  4. [string]$msolLastName = "Updater-Account",
  5. [string]$msolUpn = "svc_network-updater@yourDomain.onmicrosoft.com",
  6. [string]$msolPassword = "MyPassword#12345",
  7. [string]$msolUsageLocation = "US",
  8. [string]$azureSubscriptionName = "mySubscription",
  9. [string]$azureResourceGroupName = "Networking",
  10. [string]$azureLocalGatewayName = "LocalGateway"
  11. )
  12.  
  13. #region Login to O365 and Create User
  14. $cred = Get-Credential -Message "Enter Admin Credentials for O365..."
  15. Connect-MsolService -Credential $cred
  16.  
  17. $user = New-MsolUser -DisplayName $msolDisplayName `
  18. -FirstName $msolFirstName `
  19. -LastName $msolLastName `
  20. -UserPrincipalName $msolUpn `
  21. -UsageLocation $msolUsageLocation `
  22. -ForceChangePassword:$false `
  23. -PasswordNeverExpires:$true `
  24. -Password $msolPassword
  25. #endregion
  26.  
  27. #region Login to Azure and Add User to Local Network Gateway RBAC
  28. Login-AzureRmAccount -SubscriptionName $azureSubscriptionName
  29. $ID = Get-AzureRmResourceGroup $azureResourceGroupName | Get-AzureRmLocalNetworkGateway -Name $azureLocalGatewayName | select Id
  30. New-AzureRmRoleAssignment -Scope $ID.Id -ObjectId $user.ObjectId -RoleDefinitionName "Contributor"
  31.  
  32. <# Remove User from EVERYWHERE!
  33. Get-AzureRmRoleAssignment | Where-Object {$_.ObjectId -eq $userID} | Remove-AzureRmRoleAssignment
  34. #>
  35. #endregion
Add Comment
Please, Sign In to add comment