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 https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection # 3.Join the opened session: Import-PSSession $Alex
- go to File – Save 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.