Filip Heens
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:ErrorActionPrefere nce = "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:ErrorActionPrefere nce = "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-msolpartnercon tract -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
}
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:ErrorActionPrefere
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:ErrorActionPrefere
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-msolpartnercon
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
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 ;-)
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