Sysprep 删除所有 SQL 用户

Sysprep 删除所有 SQL 用户

我在 SQL Server(2017)上运行两个实例 - SQLEXPRESS 和 MYINSTANCE

我已向 MYINSTANCE 添加了一些用户

但是,当我在设备上运行 Sysprep 时,它会删除除和之外的所有sa内容Builtin\Users

然而,它似乎并没有对 SQLEXPRESS 用户采取任何措施。

我怎样才能防止这种删除?

这是我的无人值守文件:(出于安全考虑,部分内容已被删除)

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
    <servicing>
        <package action="configure">
            <assemblyIdentity name="Microsoft-Windows-EnterpriseSEdition" version="10.0.14393.0" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="" />
            <selection name="Microsoft-Hyper-V-ClientEdition-Package" state="false" />
        </package>
    </servicing>
    <settings pass="specialize">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <AutoLogon>
                <Password>
                    <Value>#####################################</Value>
                    <PlainText>false</PlainText>
                </Password>
                <Username>#########</Username>
                <LogonCount>4294967290</LogonCount>
                <Enabled>true</Enabled>
            </AutoLogon>
            <ComputerName>COMPACT-PC</ComputerName>
            <ProductKey>###########################</ProductKey>
            <TimeZone>GMT Standard Time</TimeZone>
        </component>
        <component name="Microsoft-Windows-SystemRestore-Main" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <DisableSR>1</DisableSR>
        </component>
    </settings>
    <settings pass="oobeSystem">
        <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <InputLocale>en-GB;</InputLocale>
            <SystemLocale>en-GB</SystemLocale>
            <UILanguage>en-GB</UILanguage>
            <UILanguageFallback>en-GB</UILanguageFallback>
            <UserLocale>en-GB</UserLocale>
        </component>
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <AutoLogon>
                <Password>
                    <Value>##################################</Value>
                    <PlainText>false</PlainText>
                </Password>
                <LogonCount>4294967290</LogonCount>
                <Username>#########</Username>
                <Enabled>true</Enabled>
            </AutoLogon>
            <FirstLogonCommands>
                <SynchronousCommand wcm:action="add">
                    <Order>9</Order>
                    <CommandLine>powercfg.exe -setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c</CommandLine>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>powercfg.exe  -SETACVALUEINDEX ########################## #################### #####################</CommandLine>
                    <Order>10</Order>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <Order>1</Order>
                    <Description>bcdedit.exe /set {current} bootstatuspolicy ignoreallfailures</Description>
                </SynchronousCommand>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>&quot;C:\Windows\System32\sysprep\sidFoldRename.vbs&quot;</CommandLine>
                    <Order>12</Order>
                </SynchronousCommand>
            </FirstLogonCommands>
            <OEMInformation>
                <Manufacturer>###########</Manufacturer>
                <SupportURL>####################</SupportURL>
                <Model>#################</Model>
            </OEMInformation>
            <OOBE>
                <NetworkLocation>Home</NetworkLocation>
                <ProtectYourPC>3</ProtectYourPC>
                <HideEULAPage>true</HideEULAPage>
                <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
                <SkipUserOOBE>true</SkipUserOOBE>
                <SkipMachineOOBE>true</SkipMachineOOBE>
            </OOBE>
            <UserAccounts>
                <LocalAccounts>
                    <LocalAccount wcm:action="add">
                        <Password>
                            <Value>#############################</Value>
                            <PlainText>false</PlainText>
                        </Password>
                        <Group>Administrators</Group>
                        <Description>######</Description>
                        <DisplayName>######</DisplayName>
                        <Name>#####</Name>
                    </LocalAccount>
                </LocalAccounts>
            </UserAccounts>
            <WindowsFeatures>
                <ShowMediaCenter>false</ShowMediaCenter>
                <ShowWindowsMail>false</ShowWindowsMail>
                <ShowWindowsMediaPlayer>false</ShowWindowsMediaPlayer>
                <ShowInternetExplorer>true</ShowInternetExplorer>
            </WindowsFeatures>
            <BluetoothTaskbarIconEnabled>true</BluetoothTaskbarIconEnabled>
        </component>
    </settings>
    <settings pass="generalize">
        <component name="Microsoft-Windows-PnpSysprep" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <PersistAllDeviceInstalls>true</PersistAllDeviceInstalls>
            <DoNotCleanUpNonPresentDevices>true</DoNotCleanUpNonPresentDevices>
        </component>
    </settings>
    <cpi:offlineImage cpi:source="wim:e:/sources/install.wim#Windows 10 Enterprise 2016 LTSB" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
</unattend>

(每个部分的用户名和密码相同)

这是用于运行 sysprep 的命令...

c:\windows\system32\sysprep\sysprep.exe /generalize /oobe /shutdown /unattend:c:\windows\system32\sysprep\myAnswerFile.xml

但它甚至可以在无需应答文件的审核模式下执行此操作。

谢谢你的帮助...

编辑

我刚刚注意到一些奇怪的事情——如果我启动服务的单用户模式,所有用户都会回来!

答案1

这是设计使然:Sysprep 将安装状态恢复到首次安装时的状态:没有用户帐户、没有配置、没有 IP 地址、没有名称、没有域成员身份。Sysprep 的最后一步是通用化,确保从映像安装的版本获得自己的用户 ID SID 等,并在安装期间运行 OOBE(开箱即用体验)。

虽然官方文档不是很详细,但你可以在 Amazon AWS 说明中找到对此的明确警告 创建自定义 Windows AMI

在你开始之前

  • 在执行 Sysprep 之前,我们建议您删除所有本地用户帐户和所有帐户配置文件,除了将在其下运行 Sysprep 的单个管理员帐户。如果您使用其他帐户和配置文件执行 Sysprep,则可能会导致意外行为,包括配置文件数据丢失或无法完成 Sysprep。

正如您所发现的,Microsoft 已经对 Sysprep 进行了调整,使其能够识别 SQL Server 安装,但是由于上述引文中提到的原因,它无法保留用户登录信息(使用已知 SID 的管理员除外)。

SQLEXPRESS 作为一个老产品可能不会受到此影响。

答案2

这里的问题是 Sysprep 更改了 Windows 用户的 SID,但不会影响 SQL Server 中的登录

这意味着 SQL Server 存储的与每个 SQL 登录与 Windows 用户匹配的 SID 不再有效 - 它仍然是旧的 SID。

这里的解决方案是创建一个脚本来运行<FirstLogonCommands>......

  1. 停止 SQL Server 服务
  2. 以单用户模式重新启动
  3. 执行一个脚本,删除每个 SQL 登录,然后使用再次添加它SQLCMD
  4. 停止 SQL Server 服务
  5. 以正常模式重新启动。

我将其作为 .BAT 文件,尽管可能有更优雅的方法。将服务器置于单用户模式是必要的,因为此时没有具有添加/删除登录权限的帐户。

我不确定为什么 SQLEXPRESS 没有受到影响。但是我猜 SQL 有点混乱,不同版本只是以不同的方式处理混乱。例如,当我在 MYINSTANCE 中以这种方式重新创建一个登录时,它没有出现。当我重新创建另一个时,它们都出现在“安全”列表中,但只有我重新创建的那个真正起作用。我怀疑虽然 SQLEXPRESS 显示所有登录,但它们可能不起作用。

相关内容