$cred = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic -AllowRedirection $ImportCmd = Import-PSSession $Session
After I have typed my credentials loading the modules and got the error message “Import-Module : There were errors in loading the format data file:Microsoft.PowerShell”.
WARNING: Your connection has been redirected to the following URI: "https://pod51053psh.outlook.com/powershell-liveid?PSVersion=2.0 " PS C:Userskevin> $ImportCmd = Import-PSSession $Session WARNING: Proxy creation has been skipped for the following command: 'TabExpansion', because it would shadow an existing local command. Use the AllowClobber parameter if you want to shadow existing local commands. Import-Module : There were errors in loading the format data file: Microsoft.PowerShell, , C:UserskevinAppDataLocalTemptmp_a97a2eff-f881-4737-82d4-4c6b63d658f6_nygoxstp.fjftmp_a97 a2eff-f881-4737-82d4-4c6b63d658f6_nygoxstp.fjf.format.ps1xml : File skipped because of the following validation excepti on: File C:UserskevinAppDataLocalTemptmp_a97a2eff-f881-4737-82d4-4c6b63d658f6_nygoxstp.fjftmp_a97a2eff-f881-4737 -82d4-4c6b63d658f6_nygoxstp.fjf.format.ps1xml cannot be loaded because the execution of scripts is disabled on this sys tem. Please see "get-help about_signing" for more details.. At line:3 char:30 + Import-Module <<<< -Name $name -Alias * -Function * -Prefix $prefix -DisableNameChecking:$disableNam eChecking -PassThru -ArgumentList @($session) + CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException + FullyQualifiedErrorId : FormatXmlUpateException,Microsoft.PowerShell.Commands.ImportModuleCommand
Solution
In error message, you can see the message “File skipped because of the following validation exception: cannot be loaded because the execution of scripts is disabled on this system”. So, to fix this issue we need to configure poweshell script ExecutionPolicy as RemoteSigned to allow all scripts and configuration files downloaded from the Internet be signed by a trusted publisher.
– Open Powershell console with elevated privilege (Run as administrator).
– Run below command to set ExecutionPolicy as RemoteSigned.
Set-ExecutionPolicy RemoteSigned -Force
Now, you can able connect Office 365 through powershell smoothly.