Link to home
Start Free TrialLog in
Avatar of Filip Heens
Filip HeensFlag for Belgium

asked on

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  

}
Avatar of becraig
becraig
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of Vasil Michev (MVP)
Vasil Michev (MVP)
Flag of Bulgaria 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 Filip Heens

ASKER

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 ;-)