Get-OrganizationConfig 关键项(Adfs*)与 OWA/ECP 访问状态,便于回滚。Get-Service adfssrv | Select-Object Name, Status








Add-AdfsRelyingPartyTrust -Name "Outlook On The Web" `
-Notes "Trust for OWA via ADFS" `
-MetadataUrl "https://mail.digitalsee.co/FederationMetadata/2007-06/FederationMetadata.xml" `
-IssuanceAuthorizationRules '@RuleTemplate = "AllowAllAuthzRule" => issue(Type = "http://schemas.microsoft.com/authorization/claims/permit", Value = "true");' `
-IssueOAuthRefreshTokensTo NoDevice


Add-AdfsRelyingPartyTrust -Name "Exchange Admin Center" `
-Notes "Trust for EAC via ADFS" `
-MetadataUrl "https://mail.digitalsee.co/FederationMetadata/2007-06/FederationMetadata.xml" `
-IssuanceAuthorizationRules '@RuleTemplate = "AllowAllAuthzRule" => issue(Type = "http://schemas.microsoft.com/authorization/claims/permit", Value = "true");' `
-IssueOAuthRefreshTokensTo NoDevice



Set-AdfsRelyingPartyTrust -TargetName "Outlook On The Web" -
IssuanceTransformRules '@RuleName = "ActiveDirectoryUserSID" c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer == "AD AUTHORITY"] => issue(store = "Active Directory", types = ("http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid"), query = ";objectSID;{0}", param = c.Value); @RuleName = "ActiveDirectoryUPN" c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer == "AD AUTHORITY"] => issue(store = "Active Directory", types = ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn"), query = ";userPrincipalName;{0}", param = c.Value);'Set-AdfsRelyingPartyTrust -TargetName "Exchange Admin Center" -
IssuanceTransformRules '@RuleName = "ActiveDirectoryUserSID" c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer == "AD AUTHORITY"] => issue(store = "Active Directory", types = ("http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid"), query = ";objectSID;{0}", param = c.Value); @RuleName = "ActiveDirectoryUPN" c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer == "AD AUTHORITY"] => issue(store = "Active Directory", types = ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn"), query = ";userPrincipalName;{0}", param = c.Value);'
c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer == "AD AUTHORITY"]
=> issue(store = "Active Directory", types = ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn"), query = ";userPrincipalName;{0}", param = c.Value);
c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer == "AD AUTHORITY"]
=> issue(store = "Active Directory", types = ("http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid"), query = ";objectSID;{0}", param = c.Value);


c:[Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", Properties["http://schemas.xmlsoap.org/ws/2005/05/identity/claimproperties/format"] == "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"]
=> issue(Type = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn", Issuer = c.Issuer, OriginalIssuer = c.OriginalIssuer, Value = c.Value, ValueType = c.ValueType);
c:[Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/email"]
=> issue(Type = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn", Issuer = c.Issuer, OriginalIssuer = c.OriginalIssuer, Value = c.Value, ValueType = c.ValueType);



# 生成Token-Signing证书
$signCert = New-SelfSignedCertificate -Subject "CN=ADFS Signing - ad09.digitalsee.co" -CertStoreLocation "Cert:\LocalMachine\My" -KeyUsage DigitalSignature -KeyAlgorithm RSA -KeyLength 2048
# 生成Token-Decrypting证书
$decCert = New-SelfSignedCertificate -Subject "CN=ADFS Encryption - ad09.digitalsee.co" -CertStoreLocation "Cert:\LocalMachine\My" -KeyUsage KeyEncipherment -KeyAlgorithm RSA -KeyLength 2048
\# 导出PFX证书
#### 5.3 导入到 Exchange
### 导出证书到Exchange服务器
cer格式:证书导入到根证书存储
```powershell
Import-Certificate -FilePath "C:\Temp\ADFSTokenSigning.cer" -CertStoreLocation "Cert:\LocalMachine\Root"
# 导入证书到My存储
$signPwd = Read-Host "输入PFX密码" -AsSecureString
Import-PfxCertificate -FilePath C:\temp\adfs-token-signing.pfx -CertStoreLocation Cert:\LocalMachine\My -Password $signPwd
$decPwd = Read-Host "输入PFX密码" -AsSecureString
Import-PfxCertificate -FilePath C:\temp\adfs-token-decrypting.pfx -CertStoreLocation Cert:\LocalMachine\My -Password $decPwdGet-ChildItem "Cert:\LocalMachine\Root" | Where-Object { $_.Thumbprint -eq "11DCC57D14D93734366917B78A03DC9712D0369F" }
Set-OrganizationConfig -AdfsIssuer "https://ad09.digitalsee.co/adfs/ls/" `
-AdfsAudienceUris @("https://mail01.digitalsee.co/owa/", "https://mail01.digitalsee.co/ecp/") `
-AdfsSignCertificateThumbprint "9A3463D65F4B5396B830431BB5794A844BDB680A"
# 创建完整的ADFS配置XML
# ⚠️ 重要:以下参数需要根据你的环境进行修改
$adfsConfig = @"
<service>
<federatedAuthentication>
<wsFederation passiveRedirectEnabled="true"
issuer="https://ad09.digitalsee.co/adfs/ls/"
realm="https://fakerealm/"
requireHttps="true" />
<cookieHandler requireSsl="true" path="/" />
</federatedAuthentication>
<certificateValidation certificateValidationMode="PeerOrChainTrust" />
<audienceUris>
<add value="https://mail01.digitalsee.co/owa/" />
<add value="https://mail01.digitalsee.co/ecp/" />
</audienceUris>
<issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<trustedIssuers>
<add thumbprint="9a3463d65f4b5396b830431bb5794a844bdb680a" name="Adfs" />
</trustedIssuers>
</issuerNameRegistry>
</service>
"@
Set-OrganizationConfig -AdfsAuthenticationConfiguration $adfsConfig
iisreset,验证 OWA/ECP 恢复至原有身份验证流程。Get-OrganizationConfig 中指纹是否与 ADFS Token-Signing 证书一致;证书是否导入至正确存储。-AdfsAudienceUris 完全一致(含末尾斜杠)。AdfsAuthenticationConfiguration 强制写入配置后 iisreset。