To avoid manually writing or copying PowerShell cmdlets for log in into the Office 365 account, we can use a script.

How it’s done ?

  • create a new Text Document;
  • add the following code:
# 1.Ask for credentials:
$LiveCred = Get-Credential
# 2.Create a new session:
$Alex = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $LiveCred -Authentication Basic -AllowRedirection
# 3.Join the opened session:
Import-PSSession $Alex
  • go to FileSave As – type a name: LoginIn.ps1 – for file type choose All Files.

Now let’s test the script:

  • start PowerShell;
  • depending on the location where you saved the script, we can use the cd command to change the directory.
Example: cd „C:Documents and SettingsAlexandruDesktop” 
  •  type . and press the Tab key until you see the script’s name and then press Enter.
  •  add your UserName and Password.

Now we are logged in into our Office 365 account and we can run various cmdlets.

Back To Top