Link to home
Start Free TrialLog in
Avatar of TechTeam2012
TechTeam2012Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Connecting to O365 connector via PowerShell

Trying to create a quick script for the helpdesk to change calendar permissions on PowerShell through the O365 connector and i was wondering what do i need so that the console doesn't close after the below is run and they can continue with running some commands.

$UserCredential = Get-Credential

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

Import-PSSession $Session

Open in new window


I've seen that running it with the -NoExit switch could work but it's a little cumbersome, is there a better way from within the script?

Help as always is appreciated!
Avatar of Jeremy Weisinger
Jeremy Weisinger

You can have the script relaunch with the -noexit parameter from within the script. Here's an example:
https://stackoverflow.com/questions/9362722/stop-powershell-from-exiting
Avatar of TechTeam2012

ASKER

I've seen that before and not having much joy with it i'm afraid.
What issues are you having?

You can edit the registry so the default behaviour is to not exit. See this post: http://blog.danskingdom.com/keep-powershell-console-window-open-after-script-finishes-running/
Thanks for getting back to me,

i ideally want a line in the PowerShell that means the helpdesk user's can continue with the commands they're going to use, ie
Get-MailboxFolderPermission -Identity "USER*:\calendar"

Open in new window


The problem with launching it from Run with the -NoExit switch is that it always needs to be linked to the same location and i don't want to start editing registrys as it might not always be on the same machine.

Ideally i just need something that runs after
Import-PSSession $Session

Open in new window

that continues with the prompt, so the helpdesk guys can continue working after the script has run.
ASKER CERTIFIED SOLUTION
Avatar of Jeremy Weisinger
Jeremy Weisinger

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
Bingo, that's worked perfectly, thanks very much!
Glad to help. :)