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

[玩转系统] 使用 PowerShell 在 AD 中创建 SharePoint 服务帐户

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

使用 PowerShell 在 AD 中创建 SharePoint 服务帐户


我现在进行了很多 SharePoint 部署。我使用 PowerShell 脚本快速创建 SharePoint 服务帐户,而不是在 Active Directory 中手动一一创建它们。从域控制器(或从安装了远程服务器管理工具的工作站)运行以下 PowerShell 脚本,一次性创建服务帐户。

[玩转系统] 使用 PowerShell 在 AD 中创建 SharePoint 服务帐户

以下是我在 SharePoint 2013/SharePoint 2010 部署中使用的服务帐户列表:

  1. SP_Setup - SharePoint 设置帐户
  2. SP_Farm - SharePoint Farm 帐户
  3. SP_Pool - 该帐户用于运行 Web 应用程序池
  4. SP_Services - 服务帐户用于运行服务应用程序
  5. SP_Crawl - 搜索服务应用程序的默认内容访问帐户
  6. SP_UserProfile - 用户配置文件导入和同步帐户
  7. SP_SuperUser - Web 应用程序超级用户帐户的缓存帐户
  8. SP_SuperReader - Web应用程序超级读者帐户的缓存帐户
  9. SQL_Admin - SQL Server 上的 SQL 管理员。用于安装 SQL Server。
  10. SQL_Services - 运行 SQL Server 服务的服务帐户

PowerShell 在 Active Directory 中创建 SharePoint 服务帐户

使用此 PowerShell 脚本自动在 Active Directory 中创建服务帐户。尽管这可以手动完成,但使用 PowerShell 将节省您的时间并确保所有帐户的创建一致。这篇博文将向您展示如何通过 PowerShell cmdlet 在 AD 中创建 SharePoint 服务帐户,使您可以更轻松地进行重复部署/配置。

以下是用于在 Active Directory 中创建 SharePoint 服务帐户的 PowerShell 脚本:


Import-Module ActiveDirectory -ErrorAction SilentlyContinue

#Set configurations
$AccountPassword = "Password1"
#Convert to Secure string 
$Password = ConvertTo-SecureString -AsPlainText $AccountPassword -Force

$Domain = "YourDomain.com"
#Specify the OU
$AccountPath= "ou=SharePoint,DC=YourDomain,DC=com"

#Create SharePoint Accounts
$Account="SP_Setup" 
New-ADUser -SamAccountName $Account -name $Account -UserPrincipalName $Account@$domain -Accountpassword $Password -Enabled $true -PasswordNeverExpires $true -path $AccountPath -OtherAttributes @{Description="Account Used to install SharePoint"}

$Account="SP_Farm" 
New-ADUser -SamAccountName $Account -name $Account -UserPrincipalName $Account@$domain -Accountpassword $Password -Enabled $true -PasswordNeverExpires $true -path $AccountPath -OtherAttributes @{Description="SharePoint Farm Account."}

$Account="SP_Pool" 
New-ADUser -SamAccountName $Account -name $Account -UserPrincipalName $Account@$domain -Accountpassword $Password -Enabled $true -PasswordNeverExpires $true -path $AccountPath -OtherAttributes @{Description="SharePoint Web Application Pools Account"}

$Account="SP_Services" 
New-ADUser -SamAccountName $Account -name $Account -UserPrincipalName $Account@$domain -Accountpassword $Password -Enabled $true -PasswordNeverExpires $true -path $AccountPath -OtherAttributes @{Description="Account to run the Service Applications"}

$Account="SP_Crawl" 
New-ADUser -SamAccountName $Account -name $Account -UserPrincipalName $Account@$domain -Accountpassword $Password -Enabled $true -PasswordNeverExpires $true -path $AccountPath -OtherAttributes @{Description="Content Access Account for the Search Service Application"}

$Account="SP_UserProfile" 
New-ADUser -SamAccountName $Account -name $Account -UserPrincipalName $Account@$domain -Accountpassword $Password -Enabled $true -PasswordNeverExpires $true -path $AccountPath -OtherAttributes @{Description="User Profile Import and Synchronization Account"}

$Account="SP_SuperUser" 
New-ADUser -SamAccountName $Account -name $Account -UserPrincipalName $Account@$domain -Accountpassword $Password -Enabled $true -PasswordNeverExpires $true -path $AccountPath -OtherAttributes @{Description="Web application super User account"}

$Account="SP_SuperReader" 
New-ADUser -SamAccountName $Account -name $Account -UserPrincipalName $Account@$domain -Accountpassword $Password -Enabled $true -PasswordNeverExpires $true -path $AccountPath -OtherAttributes @{Description=" Web application super reader account"}

$Account="SQL_Admin" 
New-ADUser -SamAccountName $Account -name $Account -UserPrincipalName $Account@$domain -Accountpassword $Password -Enabled $true -PasswordNeverExpires $true -path $AccountPath -OtherAttributes @{Description="SQL Server Admin Account"}

$Account="SQL_Services" 
New-ADUser -SamAccountName $Account -name $Account -UserPrincipalName $Account@$domain -Accountpassword $Password -Enabled $true -PasswordNeverExpires $true -path $AccountPath -OtherAttributes @{Description="Account to run SQL Server services"}

这里我直接在PowerShell脚本中指定帐户。但是,您还可以使用 CSV 文件导入服务帐户列表并在 Active Directory 中批量创建它们。

从 CSV 创建 SharePoint 服务帐户

这是我的 CSV 文件,其中填写了帐户、密码和描述:

[玩转系统] 使用 PowerShell 在 AD 中创建 SharePoint 服务帐户

用于从 CSV 创建 AD 帐户的 PowerShell 脚本:


Import-Module ActiveDirectory -ErrorAction SilentlyContinue

#Set configurations
$Domain = "YourDomain.com"
#Specify the OU
$AccountPath= "ou=SharePoint,DC=YourDomain,DC=com"

# Import the CSV File
$ServiceAccounts = Import-Csv D:\SharePoint\ServiceAccounts.csv

Foreach ($ServiceAccount in $ServiceAccounts) 
 {   
    write-host "Creating Account:"$ServiceAccount.Account
    write-host "Creating Account:"$ServiceAccount.password

    #Convert to password to Secure string 
    $AccountPassword = ConvertTo-SecureString -AsPlainText $ServiceAccount.Password -Force

    $UPN = "$($ServiceAccount.Account)@$($domain)"

    #Create SharePoint Service Accounts from CSV
    New-ADUser -SamAccountName $ServiceAccount.Account -name $ServiceAccount.Account -UserPrincipalName $UPN -Accountpassword $AccountPassword -Enabled $true -PasswordNeverExpires $true -path $AccountPath -OtherAttributes @{Description=$ServiceAccount.Description}
 }

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

取消回复欢迎 发表评论:

关灯