Link to home
Start Free TrialLog in
Avatar of o365Adm
o365Adm

asked on

Powershell session function or module.

Hi All,

We run powershell scripts through web interface to manage operational activity. Each time we run the below powershell script it loads a new session, downloads all the cmdlets which is taking time. Even for creating a new mailbox we had to wait for the session to be loaded each time.

Out application has provisioned to share runspace and maintain powershell session consitently without creating session.

Could you please help me in creating a powershell session module psm1 file so that we will it while our users access the website for the first time. In the script we will call this module only if session -eq NULL.
Avatar of o365Adm
o365Adm

ASKER

Below is the cmdlet which we use to get powershell session. We want this in a powershell module all together so that it will be easy for us to call.

$password = Get-content "C:\temp\password.txt" | convertto-securestring
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist "serviceaccount.mydomain.onmicrosoft.com",$password
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credentials -Authentication Basic -AllowRedirection -warningaction silentlycontinue
$temp = Import-PSSession $Session -allowclobber -warningaction silentlycontinue

Import-Module msonline
Connect-MsolService -Credential $Credentials -warningaction silentlycontinue
Avatar of Qlemo
You are using a PS Host (https://technet.microsoft.com/en-us/library/ee706563(v=vs.85).aspx)? In that, you should have to import the remote session once only, and have full access without redoing any import action.
Avatar of o365Adm

ASKER

Hi Qlemo,

The requested page cannot be found. May I request to resend the link or article on again.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of o365Adm

ASKER

Thank you Qlemo.