title: You must call the Connect-MsolService cmdlet before calling any other cmdlets
body: <p>I have powershell script that connects to the Msol service .When i tried to run the script it works locally(powershell commandline Vscode) but when i try to run script via Active batch it is giving me error "You must call the Connect-MsolService cmdlet before calling any other cmdlets" .</p>
  
  <pre><code> $secpasswd = ConvertTo-SecureString "" -AsPlainText -Force
   $EXOCred= New-Object System.Management.Automation.PSCredential ("",$secpasswd) 
   $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $EXOCred -Authentication Basic -AllowRedirection
   Import-PSSession $Session -AllowClobber
   $secpasswd = ConvertTo-SecureString "" -AsPlainText -Force
   $MSOCred= New-Object System.Management.Automation.PSCredential ("",$secpasswd) 
   Connect-MsolService -Credential $MSOCred
   $RoleObject = Get-MsolRole | Where-Object{$_.Name -match $roles}
   $members= Get-MsolRoleMember -RoleObjectId $RoleObject.ObjectId
  </code></pre>
  
  <p>Can anyone help as i am getting error when executing the script in Active Batch </p>