Functions/New-PartnerTenantAdminUser.ps1
function New-PartnerTenantAdminUser { param ( [Parameter(Mandatory)] [string] $TenantId ) $UserPassword = Read-Host -Prompt "Pasword" -AsSecureString $UserPassword = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($UserPassword) $UserPassword = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($UserPassword) $MsolDomains = Get-MsolDomain -TenantId $TenantId $UserDomain = $MsolDomains | Where-Object { ($_.Name -Like "*.onmicrosoft.com*") -and ($_.Name -NotLike "*mail.onmicrosoft.com*") } $UserPrincipalName = "admin.jterlouw@$($UserDomain.Name)" $Param = @{ TenantId = $TenantId UserPrincipalName = $UserPrincipalName DisplayName = "Jaap Terlouw (Admin RAM-IT)" PasswordNeverExpires = $true Password = $UserPassword UsageLocation = "NL" } New-MsolUser @Param | Select-Object UserPrincipalName, DisplayName Add-MsolRoleMember -RoleName "Company Administrator" -TenantId $TenantId -RoleMemberEmailAddress $UserPrincipalName Get-MsolAccountSku -TenantId $TenantId $License = Read-Host -Prompt "Assign license" if ($License) { Set-MsolUserLicense -UserPrincipalName $UserPrincipalName -AddLicenses $License -TenantId $TenantId } Get-MsolUser -UserPrincipalName $UserPrincipalName -TenantId $TenantId | Format-List # Get-MsolUser -UserPrincipalName $UserPrincipalName -TenantId $TenantId | Remove-MsolUser -TenantId $TenantId # Get-MsolUser -UserPrincipalName $UserPrincipalName -TenantId $TenantId -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin -TenantId $TenantId } |