Introduction
In this article, we will show
How to Bulk register Managed Account In SharePoint Using PowerShell?

What's the Managed Account in SharePoint?
A Managed Account is effectively an Active Directory user account whose credentials are managed by and contained within SharePoint. Read more at Managed
Accounts in SharePoint.
Add Managed Account In SharePoint via PowerShell
You can easily register a managed account via
New-SPManagedAccount cmdlet as below
$pass
= convertto-securestring
$Password
-asplaintext -force
$cred
= new-
object
management
.
automation
.
pscredential
$Account
,
$pass
$res
= New-SPManagedAccount -Credential
$cred
But what if you want to register a large number of accounts, it will be a boring process to add each account one by one!
so we wrote the below script that helps to bulk register Managed account in SharePoint.
Bulk Register Managed Account In SharePoint via PowerShell
You can bulk register managed account by looping for each item in CSV file as below.
PowerShell Script
#######################################################
#
Add
Add
-PSSnapin Microsoft.SharePoint.PowerShell
Set
-ExecutionPolicy
"Unrestricted"
Add
-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction Stop
#######################################################
#
Add
service account
to
managed account
function
Add
-ManagedAccount()
{
Try
{
#Get Accounts
from
CSV
Import-Csv F:\ManagedAccounts.csv | ForEach-Object {
$ServiceAccount= $_.
"Service Account"
$AccountPassword= $_.
#Get Accounts
from
CSV
Password
Write-Host
"Adding the service Account"
$ServiceAccount
"to Managed Account"
-ForegroundColor Green
$srvacount = Get-SPManagedAccount | ? {$_.UserName -eq $ServiceAccount}
if ($srvacount -eq $
null
)
{
$pass = convertto-securestring $AccountPassword -asplaintext -
force
$cred = new-object management.automation.pscredential $ServiceAccount ,$pass
$res = New-SPManagedAccount -Credential $cred
if ($res -ne $
null
)
{
Write-Host
"The"
$ServiceAccount
"has been added successfully to Managed Account"
-ForegroundColor Cyan
}
}
else
{
Write-Host
"The"
$ServiceAccount
"is already added to Managed Account"
-ForegroundColor Yellow
}
}
}
Catch
{
Write-Host $_.Exception.Message -ForegroundColor Red
break
}
}
#
Add
bulk accounts
to
managed accounts using PowerShell
Add
-ManagedAccount
The CSV file has two columns:
- Service Account.
- Password.
Note:
You can download the full script and the CSV template file from
Technet Gallerty.
How to use the script?
Before
you run this script, you should make sure that the curren,Arial,Helvetica,sans-serif;font-size:10px;background-color:#ffffff;" />