我在 Windows 2003 Server 上创建了大约 50 个用户帐户,我想将这些帐户复制到新服务器,可以吗?我没有使用 Active Directory。
帕特里克
编辑1:感谢您的回答,但是我应该在最初的问题中更具体一些。我想复制用户帐户并保留现有密码。此外,我想在跨互联网和防火墙的两台服务器之间复制帐户。是否可以简单地备份和恢复用户帐户?
答案1
命令“net user”将显示所有用户帐户的列表。如果您运行此命令并将输出通过管道传输到文件,则可以编辑该文件以将其转换为脚本来创建新服务器的帐户。使用“net help user”查看如何从批处理文件创建帐户。创建帐户后,您可能需要对帐户进行一些手动调整,但与使用 GUI 相比,这仍然节省时间。
注意:您无法提取旧密码。如果您不知道用户密码,则必须将其全部设置为某个默认值,然后逐个更改。
JR
John 的帖子提醒了我:MS 有一个名为 AddUsers 的小程序可以帮助解决此类问题。请参阅http://support.microsoft.com/kb/199878了解详情。
答案2
下面是一个 VBscript 程序,用于将本地组和用户帐户从源计算机复制到目标计算机:
Option Explicit
Dim dictGroupsNotToCreate, dictPropertiesToCopy, dictUsersToIgnore, objNetwork
Dim colSourceGroups, colDestinationGroups, objSourceGroup, objDestinationGroup, objUser
Dim colSourceAccounts, colDestinationAccounts, objSourceUser, objDestinationUser, property
' Debugging
Const DEBUGGING = True
' Source and destination computers
Const SOURCE_COMPUTER = "PC00623"
Const DESTINATION_COMPUTER = "PC00619"
' Password to set on newly create user accounts
Const DEFAULT_PASSWORD = "rh1n0s!!!"
' Constants for comparison of accounts to ignore list
Const MATCH_EXACT = 1
Const MATCH_LEFT = 2
Set dictGroupsNotToCreate = CreateObject("Scripting.Dictionary")
dictGroupsNotToCreate.Add "Administrators", MATCH_EXACT
dictGroupsNotToCreate.Add "Backup Operators", MATCH_EXACT
dictGroupsNotToCreate.Add "Guests", MATCH_EXACT
dictGroupsNotToCreate.Add "Network Configuration Operators", MATCH_EXACT
dictGroupsNotToCreate.Add "Power Users", MATCH_EXACT
dictGroupsNotToCreate.Add "Remote Desktop Users", MATCH_EXACT
dictGroupsNotToCreate.Add "Replicator", MATCH_EXACT
dictGroupsNotToCreate.Add "Users", MATCH_EXACT
dictGroupsNotToCreate.Add "Debugger Users", MATCH_EXACT
dictGroupsNotToCreate.Add "HelpServicesGroup", MATCH_EXACT
' Properties of user accounts to copy
Set dictPropertiesToCopy = CreateObject("Scripting.Dictionary")
dictPropertiesToCopy.Add "Description", True
dictPropertiesToCopy.Add "FullName", True
dictPropertiesToCopy.Add "HomeDirDrive", True
dictPropertiesToCopy.Add "HomeDirectory", True
dictPropertiesToCopy.Add "LoginHours", True
dictPropertiesToCopy.Add "LoginScript", True
dictPropertiesToCopy.Add "Profile", True
' Accounts to ignore during copying
Set dictUsersToIgnore = CreateObject("Scripting.Dictionary")
dictUsersToIgnore.Add "SUPPORT_", MATCH_LEFT
dictUsersToIgnore.Add "IUSR_", MATCH_LEFT
dictUsersToIgnore.Add "IWAM_", MATCH_LEFT
dictUsersToIgnore.Add "Administrator", MATCH_EXACT
dictUsersToIgnore.Add "Guest", MATCH_EXACT
dictUsersToIgnore.Add "HelpAssistant", MATCH_EXACT
dictUsersToIgnore.Add "ASPNET", MATCH_EXACT
' Should this account be ignored
Function IgnoreObject(Name, dictNames)
Dim strToIgnore
IgnoreObject = False
For Each strToIgnore in dictNames
' Match Exact
If (dictNames.Item(strToIgnore) = MATCH_EXACT) and (UCase(Name) = UCase(strToIgnore)) Then
IgnoreObject = True
Exit Function
End If
' Match left
If (dictNames.Item(strToIgnore) = MATCH_LEFT) and (Left(UCase(Name), Len(strToIgnore)) = UCase(strToIgnore)) Then
IgnoreObject = True
Exit Function
End If
Next' strToIgnore
End Function
Set objNetwork = CreateObject("Wscript.Network")
' Get groups on source computer and loop through them, copying as necessary
Set colSourceGroups = GetObject("WinNT://" & SOURCE_COMPUTER)
Set colDestinationGroups = GetObject("WinNT://" & DESTINATION_COMPUTER)
colSourceGroups.Filter = Array("group")
For Each objSourceGroup in colSourceGroups
If IgnoreObject(objSourceGroup.Name, dictGroupsNotToCreate) = False then
If (DEBUGGING) Then WScript.Echo "Creating Group: " & objSourceGroup.Name
Set objDestinationGroup = colDestinationGroups.Create("group", objSourceGroup.Name)
objDestinationGroup.Put "Description", objSourceGroup.Get("Description")
objDestinationGroup.SetInfo
Else
If (DEBUGGING) Then WScript.Echo "Ignoring Group: " & objSourceGroup.Name
End If
Next ' objSourceGroup
' Get accounts on source computer and loop through them, copying as necessary
Set colSourceAccounts = GetObject("WinNT://" & SOURCE_COMPUTER)
set colDestinationAccounts = GetObject("WinNT://" & DESTINATION_COMPUTER)
colSourceAccounts.Filter = Array("user")
For Each objSourceUser In colSourceAccounts
If IgnoreObject(objSourceUser.Name, dictUsersToIgnore) = False Then
If (DEBUGGING) Then WScript.Echo "Copying account: " & objSourceUser.Name
On Error Resume Next
Set objDestinationUser = colDestinationAccounts.Create("user", objSourceUser.Name)
objDestinationUser.SetPassword DEFAULT_PASSWORD
objDestinationUser.SetInfo
' Copy properties from source user to destination user
For Each property in dictPropertiesToCopy
If (DEBUGGING) then WScript.Echo " Copying property " & property & " (" & objSourceUser.Get(property) & ")"
objDestinationUser.Put property, objSourceUser.Get(property)
objDestinationUser.SetInfo
Next ' property
' Put user into destination groups
For Each objSourceGroup In colSourceGroups
For Each objUser In objSourceGroup.Members
If UCase(objUser.Name) = Ucase(objSourceUser.Name) Then
If (DEBUGGING) Then WScript.Echo "Adding user " & objSourceUser.Name & " to group " & objSourceGroup.Name
Set objDestinationGroup = GetObject("WinNT://" & DESTINATION_COMPUTER & "/" & objSourceGroup.Name & ",group")
objDestinationGroup.Add(objDestinationUser.aDSPath)
Else
If (DEBUGGING) Then WScript.Echo "User " & objSourceUser.Name & " is not a member of group " & objSourceGroup.Name
End If
Next ' objUser
Next 'objSourceGroup
Else
If (DEBUGGING) Then WScript.Echo "Ignoring account: " & objSourceUser.Name
End If
Next ' objSourceUser
快速浏览:
- 设置 SOURCE_COMPUTER 和 DESTINATION_COMPUTER 名称
- 设置 DEFAULT_PASSWORD(将分配给新创建的用户帐户)
- 将不应在目标计算机上创建的任何本地组名添加到 dictGroupsNotToCreate 列表中。MATCH_EXACT 表示组名完全匹配。MATCH_LEFT 表示仅匹配组名的最左边部分(即,假设名称匹配后有一个“*”)。
- 将不应在目标计算机上创建的任何本地用户名添加到 dictUsersToIgnore 列表中。MATCH_EXACT 和 MATCH_LEFT 与 dictGroupsNotToCreate 列表具有相同的含义(即“IUSR_”与 MATCH_LEFT 意味着不会在目标计算机上创建以“IUSR_”开头的任何用户帐户)。
您必须使用有权在目标计算机上创建帐户的凭据来执行此脚本。
默认情况下,为用户帐户复制的属性列在 dictPropertiesToCopy 列表中。我选择了最常见的属性。
该脚本已经过充分测试,但我还没有在生产环境中使用过。它不会对源服务器进行任何更改,因此您可以放心运行它,而不必担心损坏源服务器。
(不,群体人口算法一点儿也不有效。如果这让你感到困扰,那么你已经知道足够多的信息来更好地重新实现它……>微笑<)
答案3
过去,我使用 Microsoft 的命令行实用程序,它允许您将帐户(包括密码哈希)转储到文本文件,然后可以将其导入另一台机器。不幸的是,我记不起它的名字了。
答案4
你可能会给移动用户尝试一下 2003 资源工具包中的功能。通读之后,我发现它似乎是为了在域之间移动用户而设计的,但我可以在 Google 上找到有关它用于本地 -> 域移动的参考资料。这让我想知道本地到本地是否也可以实现。