I recently wrote this script that creates an O365 mailbox within a hybrid exchange environment, creating all the necessary attributes etc in exchange and AD

Log all output to a local logfile, that is unique each time and won’t get overwritten

Clear output from the screen to prevent previous command being sent as first name

Prompt user to enter the details of the new account

Format the AD fields in the right way

Get credentials for the new user account and the connection to the on-prem exchange server

Connect to on-prem exchange and create mailbox

Disconnect from exchange and stop logging