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

[玩转系统] 如何使用 PowerShell 更改 SharePoint Server 中的服务帐户?

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

如何使用 PowerShell 更改 SharePoint Server 中的服务帐户?


在 SharePoint 2016 中更改服务帐户

您想要更改 SharePoint 中的服务帐户吗?也许您最近更改了域名并需要更新所有服务帐户引用。在本指南中,我们将向您展示如何快速轻松地更改 SharePoint 中的服务帐户。我还将分享如何使用 PowerShell 更改服务帐户。

如果您已创建新的托管帐户或想要更改托管帐户与 SharePoint 2016 Services 的映射,请转到:

  • 中央行政>>安全
  • 在“常规安全性”部分下,单击“配置服务帐户”。
  • 从下拉列表中选择适当的服务和服务帐户。

    [玩转系统] 如何使用 PowerShell 更改 SharePoint Server 中的服务帐户?

  • 单击“确定”保存更改

了解更多:在 SharePoint 2016 中配置托管帐户

PowerShell方式:如何更改SharePoint 2013/2016中的服务帐户?

为什么?因为并非所有帐户都可以通过 SharePoint 管理中心 UI 进行更改。以下是我使用 PowerShell 更改 SharePoint 中各种服务帐户的脚本。请注意,我们必须处理四种类型的服务帐户:

  1. SharePoint 服务实例,例如分发缓存、窗口令牌服务声明等
  2. SharePoint 场服务
  3. 服务应用程序的AppPool帐户
  4. Web 应用程序的 AppPool 帐户

[玩转系统] 如何使用 PowerShell 更改 SharePoint Server 中的服务帐户?

用于更改 SharePoint 中的服务帐户的 PowerShell 脚本(例如分发缓存服务)


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom Function to change Service account of given service
Function Set-ServiceIdentity($svc, $UserName)
{
    #Get the current service account
    $ProcessIdentity = $svc.Service.ProcessIdentity
    
    if ($ProcessIdentity.Username -ne $UserName) 
    {
       $ProcessIdentity.Username = $UserName
       $ProcessIdentity.Update()
       Write-Host "Service Account Set!"
    }
}

#Get the Service
$Service = Get-SPServiceInstance | Where {$_.TypeName -eq "Claims To Windows Token Service"}

#Call the function to Set "Local System" Identity to given service
Set-ServiceIdentity $Service "NT AUTHORITY\SYSTEM"

上面的脚本更改指定服务的服务帐户。

如何更改 SharePoint 2013 中的服务器场服务帐户

我们仍然依赖 STSADM 工具来更新 SharePoint 2013 的 Farm 帐户。使用此命令行更新 SharePoint 场的服务帐户凭据:
stsadm -o updatefarmcredentials -userlogin “DOMAIN\username” -password “Password here”

更改服务应用程序池的服务帐户:

要更改应用程序池的服务帐户,请使用以下 PowerShell 脚本:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom Function to change Service account of given service
Function Set-ServiceAppPoolIdentity($SvcAppPool, $UserName)
{
    if ($SvcAppPool.ProcessAccountName -ne $UserName) 
    {
       Set-SPServiceApplicationPool $SvcAppPool -Account $UserName
       Write-Host "Application Pool Service Account Updated!"
    }
}

#Get the Service
$SvcAppPool = Get-SPServiceApplicationPool | Where {$_.Name -eq "Service Application App Pool"}

#Call the function to Set "Local System" Identity to given service
Set-ServiceAppPoolIdentity $SvcAppPool "Crescent\SP2016Admin"

更改 Web 应用程序应用程序池帐户:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom Function to change Service account of Web App Pool
Function Set-WebAppPoolIdentity($WebAppPool, $UserName)
{
    if ($WebAppPool.ManagedAccount.UserName -ne $UserName) 
    {
       #Get the Managed Account
       $ManagedAccount= Get-SPManagedAccount $UserName
       #Set the Managed Account
       $WebAppPool.ManagedAccount = $ManagedAccount
       $WebAppPool.Update()
       Write-Host "Web Application App Pool Account Updated!"
    }
}

#Get Web App's App Pool
$WebAppPool = (Get-SPWebApplication "https://intranet.crescent.com").ApplicationPool

#Call the function to Set the Managed Account to Web App Pool
Set-WebAppPoolIdentity $WebAppPool "Crescent\SPAdmin"

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

取消回复欢迎 发表评论:

关灯