-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSet-ServiceIdentityForSPTraceV4Service.ps1
More file actions
50 lines (35 loc) · 1.48 KB
/
Set-ServiceIdentityForSPTraceV4Service.ps1
File metadata and controls
50 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<#
.SYNOPSIS
Specify a new service identity for the SPTraceV4 Windows Service.
.DESCRIPTION
Specify a new service identity for the SPTraceV4 Windows Service.
.NOTES
File Name: Set-ServiceIdentityForSPTraceV4Service.ps1
Version : 1.0
.PARAMETER AccountName
Specifies the name of the account which will be used (domain\name).
.EXAMPLE
PS > .\Set-ServiceIdentityForSPTraceV4Service.ps1 -AccountName "westeros\sp_service"
#>
[CmdletBinding()]
param(
[parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $false)]
[string]$AccountName
)
# Load the SharePoint PowerShell snapin if needed
if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -EA SilentlyContinue) -eq $null) {
Write-Host "Loading the SharePoint PowerShell snapin..."
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
# Get the tracing service.
$svc = (Get-SPFarm).Services | ? { $_.Name -eq "SPTraceV4" }
# Get the managed account from SharePoint
$svcIdentity = Get-SPManagedAccount $AccountName
# Set the tracing service to run under the managed account. $svc.ProcessIdentity.CurrentIdentityType = "SpecificUser"
$svc.ProcessIdentity.ManagedAccount = $svcIdentity
$svc.ProcessIdentity.Update()
# This actually changes the "Run As" account of the Windows service.
$svc.ProcessIdentity.Deploy()
# Add the domain account to the local "Performance Log Users" group
$Domain, $User = $AccountName.Split("\")
([ADSI]("WinNT://$env:COMPUTERNAME/Performance Log Users,group")).Add("WinNT://$Domain/$User")