当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 新-MsolServicePrincipalCredential

作者:精品下载站 日期:2024-12-14 06:27:09 浏览:14 分类:玩电脑

新-MsolServicePrincipalCredential


PowerShell 中的 New-MsolServicePrincipalCredential cmdlet 向 Microsoft Office 365 中的服务主体添加新凭据。可以使用对象 ID、应用主体 ID 或服务主体名称 (SPN) 获取服务主体。

下面给出了向服务主体添加凭证的语法。

New-MsolServicePrincipalCredential
   -ObjectId <Guid>
   -ServicePrincipalName <String>
   -AppPrincipalId <Guid>
   [-Type <ServicePrincipalCredentialType>]
   [-Value <String>]
   [-StartDate <DateTime>]
   [-EndDate <DateTime>]
   [-Usage <ServicePrincipalCredentialUsage>]
   [-TenantId <Guid>]
   [<CommonParameters>]

在本文中,我们将讨论如何在 PowerShell 中使用 New-MsolServicePrincipalCredential cmdlet 向服务主体添加新凭据。

如何向服务主体添加凭据

若要向 Office 365 中的服务主体添加凭据,请使用带有 -ServicePrincipalName 参数的 New-MsolServicePrincipalCredential cmdlet。

-ServicePrincipalName 参数指定要添加凭据的服务主体的名称。

New-MsolServicePrincipalCredential -ServicePrincipalName "ShellGeek/ShellApp.com" 

此命令将凭证或密钥添加到名为“ShellGeek/ShellApp.com”的现有服务主体。在这种情况下,会为此凭据生成对称密钥,并使用服务主体名称值“ShellGeek/ShellApp.com”将其添加到服务主体中。

如何将现有凭据添加到服务主体

要将现有凭据添加到服务主体,请将现有证书与 New-MsolServicePrincipalCredential cmdlet 结合使用。

# creates an instance of the X509Certificate classificate
$Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate

# Import the X509Certificate
$Certificate.Import("C:\shellapp.cer")

# Retrieve the raw binary data of certificate
$BinCert = $Certificate.GetRawCertData()

# Converts the binary data of certificate to a Base64-encoded string
$CredValue = [System.Convert]::ToBase64String($binCert);

# Create a new service principal credential in Azure AD
New-MsolServicePrincipalCredential -ServicePrincipalName "ShellGeekApp/ShellApp.com" -Type asymmetric -Value $CredValue -StartDate $Certificate.GetEffectiveDateString() -EndDate $Certificate.GetExpirationDateString()

在上面的 PowerShell 脚本中,它将名为 shellapp.cer 的现有证书添加到服务主体名称值“ShellGeekApp/ShellApp.com”中。

如何注册本地 Exchange 服务器

要注册本地 Exchange Server,请使用带有 -AppPrincipalId-Type-Value 参数的 New-MsolServicePrincipalCredential cmdlet。

-AppPrincipalId 参数指定要添加凭据的服务主体的应用程序 ID。 -Type 参数指定所使用的凭据类型。 -Value 参数指定凭证的值。

New-MsolServicePrincipalCredential -AppPrincipalId  -Type asymmetric -Value $CredValue

此命令注册本地 Exchange Server,以便在 Exchange Server 和 Microsoft Azure Active Directory 服务(例如 Office 365)之间进行通信。 -CredValue 包含用于表示本地 Exchange 服务器的 base64 编码的公共 X509 证书。

结论

我希望上述有关 PowerShell 中的 New-MsolServicePrincipalCredential cmdlet 向服务主体添加凭据密钥的文章对您有所帮助。

您可以在 ShellGeek 主页上找到有关 PowerShell Active Directory 命令和 PowerShell 基础知识的更多主题。

相关链接

获取 MsolServicePrincipalCredential

删除 MsolServicePrincipalCredential

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯