'Microsoft Login Check

I'm new to Powershell. I want to know how to do a check if the user log into their account successfully and if not loop back to the beginning.

Thank you!

if(-not (Get-MsolDomain -ErrorAction SilentlyContinue))
  {
    #Start Msol login session
    Import-Module MSOnline
    Connect-MsolService
    "Login Successful"
  }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source