[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 779
  • Last Modified:

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  

}
0
Filip Heens
Asked:
Filip Heens
1 Solution
 
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
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now