O365 powershellscript not working when using the -tenantid parameter

Hi, I"m trying to run this script for some of the tenants where we are Delegated Admin for

The script works fine aslong as I'm not using the -tentantid parameter
But as soon as I add the tenant part, it stops working.
Does any body has a clue what I'm doing wrong?


Working Script without -tenantid
###########################################################"

$global:ErrorActionPreference = "SilentlyContinue"
Get-PSSession | Remove-PSSession
Set-ExecutionPolicy Unrestricted
$LiveCred = Get-Credential $customer
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-PSSession $Session
Connect-MsolService -Credential $LiveCred

$AllDomains = @()
$AllDomains += "tnefdomainA.be"
$AllDomains += "tnefdomainB.be"
$AllDomains += "tnefdomainC.be"

      #set tnef for alle the domains
      foreach ($Domain in $AllDomains) {
      New-RemoteDomain -Name "$Domain" -DomainName "$Domain"
      Set-RemoteDomain -Identity "$Domain" -TNEFEnabled "$false"
      }

Get-RemoteDomain | Format-Table -Property Domainname,WhenChanged, TNEFEnabled  


###########################################################"
###########################################################"

Script with TentantIDparameter
###########################################################"
$Allcustomers = @()
$Allcustomers += "domain1.com"
$Allcustomers += "domain2.com"
$Allcustomers += "domain3.com"

$global:ErrorActionPreference = "SilentlyContinue"

Get-PSSession | Remove-PSSession
Set-ExecutionPolicy Unrestricted
$LiveCred = Get-Credential $customer
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-PSSession $Session
Connect-MsolService -Credential $LiveCred

foreach ($customerdomain in $Allcustomers) {
#get customer Tenant Identity
$tenID=(get-msolpartnercontract -domain $customerdomain).tenantId.guid
write-host "We're doing " $customerdomain "with Tenant ID = "$tenID "now"
$AllDomains = @()
$AllDomains += "tnefdomainA.be"
$AllDomains += "tnefdomainB.be"
$AllDomains += "tnefdomainC.be"

      #set tnef for alle the domains
      foreach ($Domain in $AllDomains) {
      New-RemoteDomain -Name "$Domain" -DomainName "$Domain" -tenantID "$tenID"
      Set-RemoteDomain -Identity "$Domain" -TNEFEnabled "$false" -tenantID "$tenID"
      }

Get-RemoteDomain -tenantID "$tenID" | Format-Table -Property Domainname,WhenChanged, TNEFEnabled  

}
LVL 2
Filip HeensAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

becraigCommented:
That is not a valid parameter as far as I can tell:

http://msdn.microsoft.com/library/ff326162%28v=exchg.150%29.aspx

http://www.powershellcenter.com/index.php/powershell-commands/722-get-remotedomain

you probably are looking for the organization ID
0
Vasil Michev (MVP)Commented:
I assume you are a partner and you want to manage settings on behalf of your customer? Unfortunately, for Exchange Online you must use account from the same tenant. Changing the tenantID is only available for the WAAD cmdlets, not for EO PowerShell.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Filip HeensAuthor Commented:
Danm, not what I wanted to hear, but if it is like that I'll have to find another way to do what I want ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.