Reputation: 318
I'm trying to build a script where i'm using delegated admin rights. And what I have working is this.
$ConnectionUri = "https://ps.outlook.com/powershell-liveid?DelegatedOrg=$TenantDefaultDomainName"
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $ConnectionUri -Credential $Office365Credentials -Authentication Basic -AllowRedirection
Import-PSSession $Session -AllowClobber
And this is great and connects just fine but my impression is that it's the old way of doing it as some cmdlets just plain don't work with delegation. An example being that I wanted to get the name of the calendar of a user and tried to do so using
Get-MailboxFolderStatistics -Identity $user -FolderScope Calendar
But I get an error on proxy command saying delegated user should be null. So instead I wanted to try using the new cmdlet but could barely find any information about delegation, following the reference here: https://learn.microsoft.com/en-us/powershell/module/exchange/connect-exchangeonline?view=exchange-ps
I came up with this syntax but it doesn't work at all.
Connect-ExchangeOnline -DelegatedOrganization $TenantDefaultDomainName -Credential $MyOffice365PartnerCredentials
Here's the error i'm getting.
New-ExoPSSession : One or more errors occurred.
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.4\netFramework\ExchangeOnlineManagement.psm1:475 char
:30
+ ... PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-ExoPSSession], AggregateException
+ FullyQualifiedErrorId : System.AggregateException,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession
Upvotes: 0
Views: 1851
Reputation: 318
I opened an issue on GitHub seeing as this couldn't be the intended behaviour and @chrisda came to my rescue with the response
"this is a shot in the dark, but try using the -UserPrincipalName parameter with Connect-ExchangeOnline:"
Connect-ExchangeOnline -DelegatedOrganization $TenantDefaultDomainName -UserPrincipalName <MyOffice365PartnerUPN>
Mysteriously this works and while using connect-exchangeonline you can use all the normal commands like get-mailboxfolderstatistics that don't work with the old partner method I mentioned first in my question. Hope this helps someone other than me, there is no reference for any of this in the MS documentation or any other place on the internet that I could find.
Reference: https://github.com/MicrosoftDocs/office-docs-powershell/issues/7458
Upvotes: 1