Sign In
Sethu's blog
dev@sqlservr.microsoft
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Common Tasks
Blog Home
Email Blog Author
About
Share this
RSS for comments
RSS for posts
Atom
Search Form
Advanced search options...
Search In:
Everything
Blogs
Forums
People
Groups
Places
Pages
Date range:
All Time
Last Year
Last 6 Months
Last 3 Months
Last Month
Last Week
Last Two Days
Tag Cloud
Extended Events
Policy Based Management
PowerShell
Resource Governor
SMO
SQL Agent
SQL Server
SQL Server 2008
Troubleshooting
Monthly Archives
Archives
January 2012
(1)
December 2011
(1)
July 2011
(1)
June 2011
(1)
February 2011
(1)
December 2010
(1)
November 2010
(1)
October 2010
(2)
September 2010
(1)
June 2010
(1)
February 2010
(1)
September 2009
(1)
April 2009
(1)
October 2008
(1)
July 2008
(1)
June 2008
(5)
Change Service Account Password for Sql Server / SQL Agent Accounts
MSDN Blogs
>
Sethu's blog
>
Change Service Account Password for Sql Server / SQL Agent Accounts
Change Service Account Password for Sql Server / SQL Agent Accounts
Sethu Srinivasan
3 Feb 2010 6:55 PM
Comments
0
changeSvcAcct.ps1
###########################################################################################
# Scenario:Change Service account for SQL Server, Agent services
#
# How to use this powershell script:
# - Launch SQL Server PowerShell ( Start -> Run -> sqlps.exe)
# - Copy the following powershell script and paste it in powershell window
###########################################################################################
# Change Service Account Password for Sql Server / SQL Agent Accounts
# note: if needed, this helper can be extended to AS, RS services
function
ChangeServiceAccount
{
Param
([
string
]
$machineName
=
$
(
Read-Host
"MachineName"
)
,
[
string
]
$instanceName
=
$
(
Read-Host
"Instance name(Ex: DEFAULT / SQLINST1)"
)
,
[
string
]
$serviceType
=
$
(
Read-Host
"Service Type (Ex:SqlServer / SqlAgent)"
),
[
string
]
$userAccountName
=
$
(
Read-Host
"Account Name (Ex:Domain\user)"
),
[
string
]
$password
=
$
(
Read-Host
"Password:"
)
)
if
([
String
]::
IsNullOrEmpty
(
$machineName
))
{
write-error
"Machine name is not valid"
return
}
if
([
String
]::
IsNullOrEmpty
(
$instanceName
))
{
write-error
"instance name is not valid"
return
}
$serviceName
=
""
if
(
$serviceType
-
eq
"SqlServer"
)
{
if
(
$instanceName
-
eq
"DEFAULT"
)
{
$serviceName
=
"MSSQLSERVER"
}
else
{
$serviceName
=
"MSSQL$"
+
$instanceName
}
}
if
(
$serviceType
-
eq
"SqlAgent"
)
{
if
(
$instanceName
-
eq
"DEFAULT"
)
{
$serviceName
=
"SQLSERVERAGENT"
}
else
{
$serviceName
=
"SqlAgent$"
+
$instanceName
}
}
$PSPath
=
"\SQL\"
+
$machineName
$machine
=
get-item
$PSPath
write-host
"Changing service account for"
write-host
"SQL Instance:"
$machineName
"\"
$instanceName
write-host
"Service type: "
$serviceType
write-host
"User account:"
$userAccountName
write-host
"Service Name:"
$serviceName
## DevNote: - using a key that has "$" does not work as expected
## $serviceObject= $machine.ManagedComputer.Services[$serviceName]
## following is the workaround
foreach
(
$svc
in
$machine
.
ManagedComputer
.
Services
)
{
if
(
$svc
.
Name
-
eq
$serviceName
)
{
$serviceObject
=
$svc
break
}
}
$serviceObject
.
SetServiceAccount
(
$userAccountName
,
$password
)
write-host
"Account changed!"
}
ChangeServiceAccount
# This posting is provided "AS IS" with no warranties, and confers no rights.
# Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm
0 Comments
SQL Server 2008
Leave a Comment
Name
Comment
Please add 7 and 3 and type the answer here:
Post