Import-PSSession : The runspace state is not valid for this operation
Import-PSSession : The runspace state is not valid for this operation

Today after connecting to Office 365 via power shell, I want to get some info of the mailbox so tried to run the script Get-Mailbox. But it throws me an error every time I tried to run the command

Get-mailbox: The term ‘get-mailbox’ is not recognized as the name of a cmdlet
get-mailbox not recognized - paayi
get-mailbox not recognized – paayi

To solve this upper problem, I researched that we need to run, Import-PSSession command which provides us with lots of more commands for that particular session. I just typed this command and got this error.

import-pssession error
import-pssession error

I researched a lot but found no solution. After 15 mins my PowerShell connection timeout happened. Then I thought let’s try one more time, but this time altogether. Below is the whole command what you need to post in your PowerShell window and hit run.

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 
https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential 
-Authentication Basic –AllowRedirection
Import-PSSession $session

You will get this result

Result
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
WARNING: The names of some imported commands from the module 
'tmp_zdv2hsce.qkw' include unapproved verbs that
might make them less discoverable. To find the commands with unapproved verbs, 
run the Import-Module command
again with the Verbose parameter. For a list of approved verbs, type Get-Verb.

ModuleType Version Name ExportedCommands 
---------- ------- ---- ---------------- 
Script 1.0 tmp_zdv2hsce.qkw {Add-AvailabilityAddressSpace, Add-Distribution...
ran import-pssession command
ran import-pssession command

Means It’s successful. Please leave a comment or ask the question if you need more help.

Email Getting Forwarded-NDR message-X-MS-Exchange-Inbox-Rules-Loop

Written by – Yashdeep Sahni

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.