How to create a service account via Microsoft PowerShell

How to connect to Microsoft Online using PowerShell

Connect to Microsoft Online using PowerShell and execute the following, where <UserPrincipalName> and <Password> are the username and temporary password (that you will be forced to change upon logging on for the first time) for the AskCody service account:

New-MSolUser -DisplayName "Service Account for AskCody" -UserPrincipalName <UserPrincipalName> -Password <Password> -PasswordNeverExpires $true

Then create a new role group, where <GroupName> is the name of the group and <UserPrincipalName> is the username of the AskCody service account:

New-RoleGroup -Name "<GroupName>" -Roles ApplicationImpersonation -Members "<UserPrincipalName>"

(If you are in Office 365, and your tenant has not yet been hydrated, you must run the Enable-OrganizationCustomization PowerShell cmdlet before you can use role-based access control features.)

Finally, log on to using the service account and set the actual password that will be used.