Nejnovší verze tohoto skriptu je ve formě funkce Prepare-SPWebServer jako součást mé knihovny ADLAB na adrese: https://www.sevecek.com/files/ADLAB
Hurá. Konečně se mi podařilo to celé dokončit. Už to nemusím klikat ručně.
Když instalujete SharePoint, ani jeho SharePoint Products Configuration Wizard, ani když to provádíte pomocí New-SPConfigurationDatabase a Connect-SPConfigurationDatabase, neprovede se všechno, co se musí udělat. MS trošku podcenil instalaci SharePointu pod obyčejné uživatele - což sám přitom doporučuje a navíc sám SharePoint hlásí chyby, když to není splněno.
Už jsem tu jednou psal o nastavení oprávnění pro DCOM v případě služby Search. Ale to je jen jedna malinká součást mnohem většího počtu nastavení, která se musí udělat ručně. Tak jsem si na to konečně udělal skript. Hlavní čelendž byla to zabezpečení DCOMu.
Takže tu je můj skript. Ke stažení je to jako .TXT soubor tu (je to ale PowerShell).
Ještě než pustíte New-SPConfigurationDatabase nebo Connect-SPConfigurationDatabase
Nějaká příprava. Všiměte si, že skript vytváří SQL aliasy. Samozřejmě si to musíte trošku upravit, ale rámcově je to tu k dispozici. Skript je pro PowerShell a opakuji, musí se to přizpůsobit!
REG ADD 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo'
'/v' "spconfig" '/t' 'REG_SZ' /f /d "DBMSSOCN,db1\spconfig"
REG ADD 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo'
'/v' "spcontent" '/t' 'REG_SZ' /f /d "DBMSSOCN,db1\spcontent"
REG ADD 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo'
'/v' "spservices" '/t' 'REG_SZ' /f /d "DBMSSOCN,db1\spservices"
REG ADD 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\SuperSocketNetLib'
'/v' "Encrypt" '/t' 'REG_DWORD' /f '/d' 1
REG ADD 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo'
'/v' "spconfig" '/t' 'REG_SZ' /f /d "DBMSSOCN,db1\spconfig"
REG ADD 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo'
'/v' "spcontent" '/t' 'REG_SZ' /f /d "DBMSSOCN,db1\spcontent"
REG ADD 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo'
'/v' "spservices" '/t' 'REG_SZ' /f /d "DBMSSOCN,db1\spservices"
REG ADD 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Client\SuperSocketNetLib'
'/v' "Encrypt" '/t' /f 'REG_DWORD' '/d' 1
& $env:windir\system32\inetsrv\appcmd.exe delete site "default web site"
& $env:windir\system32\inetsrv\appcmd.exe list apppool '/xml' | `
& $env:windir\system32\inetsrv\appcmd.exe delete apppool /in
& $env:windir\system32\inetsrv\appcmd.exe set config '/section:httpLogging' `
'/dontLog:FAlse' '/selectiveLogging:LogAll'
& $env:windir\system32\inetsrv\appcmd.exe set config '/section:sites' `
'-siteDefaults.logFile.logExtFileFlags:Date,Time,ClientIP,UserName,SiteName,
ComputerName,ServerIP,Method,UriStem,UriQuery,HttpStatus,Win32Status,BytesSent,
BytesRecv,TimeTaken,ServerPort,UserAgent,Cookie,Referer,ProtocolVersion,Host,
HttpSubStatus'
& $env:windir\system32\inetsrv\appcmd.exe set config '/section:sites' `
'-siteDefaults.logFile.logFormat:W3C'
& $env:windir\system32\inetsrv\appcmd.exe set config '/section:sites' `
'-siteDefaults.logFile.Directory:E:\IIS-Logs'
No a potom, co provedete New-SPConfigurationDatabase nebo Connect-SPConfigurationDatabase
... je potřeba pokračovat právě na ta oprávnění pro DCOM, dodělat různé registrové klíče a hlavně je také správně zabezpečit
function Set-RegPermissions ( [string] $key, [string] $user )
{
$keyObj = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey( `
$key, `
[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree, `
[System.Security.AccessControl.RegistryRights]::ChangePermissions `
)
$acl = $keyObj.GetAccessControl()
$inherit = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor `
[System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$rule = New-Object System.Security.AccessControl.RegistryAccessRule ( `
$user, `
"FullControl", `
$inherit, `
'None', `
"Allow" `
)
$acl.SetAccessRule($rule)
$keyObj.SetAccessControl($acl)
}
function Adjust-Privilege ( [int] $privilege, [bool] $enable )
{
$adjustPrivilege = @"
using System;
using System.Runtime.InteropServices;
namespace Win32Api {
public class NtDll {
[DllImport("ntdll.dll", EntryPoint="RtlAdjustPrivilege")]
public static extern int RtlAdjustPrivilege(
ulong Privilege,
bool Enable,
bool CurrentThread,
ref bool Enabled
);
}
}
"@
Add-Type -TypeDefinition $adjustPrivilege -PassThru
$enabledBool = $enable
$res = [Win32Api.NtDll]::RtlAdjustPrivilege($privilege, $true, $false, [ref] $enabledBool)
}
function Take-RegOwnership ( [string] $key )
{
Adjust-Privilege 9 $true
$keyObj = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey( `
$key, `
[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree, `
[System.Security.AccessControl.RegistryRights]::TakeOwnership `
)
$acl = $keyObj.GetAccessControl()
$acl.SetOwner([System.Security.Principal.NTAccount] ".\Administrators")
$keyObj.SetAccessControl($acl)
}
REG ADD 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VSS\Diag\SPSearch4 VSS Writer' /ve /f
REG ADD 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VSS\Diag\SharePoint Services Writer' /ve /f
REG ADD 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SQMServiceList' /ve /f
Set-RegPermissions 'SYSTEM\CurrentControlSet\Services\VSS\Diag\SPSearch4 VSS Writer' "WSS_ADMIN_WPG"
Set-RegPermissions 'SYSTEM\CurrentControlSet\Services\VSS\Diag\SharePoint Services Writer' "WSS_ADMIN_WPG"
Set-RegPermissions 'SYSTEM\CurrentControlSet\Control\SQMServiceList' "Administrators"
Take-RegOwnership 'Software\Classes\AppId\{000C101C-0000-0000-C000-000000000046}'
Take-RegOwnership 'Software\Classes\AppId\{61738644-F196-11D0-9953-00C04FD919C1}'
Set-RegPermissions 'Software\Classes\AppId\{000C101C-0000-0000-C000-000000000046}' "Administrators"
Set-RegPermissions 'Software\Classes\AppId\{61738644-F196-11D0-9953-00C04FD919C1}' "Administrators"
function Set-DCOMLaunchPermissions ( [string] $appID, [string] $user, [string] $domain )
{
$app = Get-WmiObject -Query ('SELECT * FROM Win32_DCOMApplicationSetting WHERE AppId = "{0}"' -f $appId) `
-EnableAllPrivileges
$sdRes = $app.GetLaunchSecurityDescriptor()
$sdRes
$sd = $sdRes.Descriptor
$trustee = ([wmiclass] 'Win32_Trustee').CreateInstance()
$trustee.Domain = $domain
$trustee.Name = $user
$fullControl = 31
$localLaunchActivate = 11
$ace = ([wmiclass] 'Win32_ACE').CreateInstance()
$ace.AccessMask = $localLaunchActivate
$ace.AceFlags = 0
$ace.AceType = 0
$ace.Trustee = $trustee
[System.Management.ManagementBaseObject[]] $newDACL = $sd.DACL + $ace
$sd.DACL = $newDACL
$app.SetLaunchSecurityDescriptor($sd)
}
Set-DCOMLaunchPermissions '{000C101C-0000-0000-C000-000000000046}' 'WSS_ADMIN_WPG' $null
Set-DCOMLaunchPermissions '{61738644-F196-11D0-9953-00C04FD919C1}' 'WSS_ADMIN_WPG' $null
icacls e: /Grant wss_wpg:R
Set-SPDiagnosticConfig -LogLocation E:\SP-Logs
Initialize-SPResourceSecurity
Install-SPHelpCollection -All
Install-SPService
Install-SPFeature -AllExistingFeatures
Install-SPApplicationContent
Tak snad se to bude někomu hodit :-)