任何人都有一个脚本来删除特定的本地Windowsconfiguration文件?

我正在寻找Powershell(首选)脚本或.CMD或.VBS,以删除工作站(WinXP)或terminal服务器(2000,'03或'08)上的特定用户configuration文件。 我知道所有关于delprof实用程序…只允许您删除基于一段时间的不活动。 我想要一个脚本来:

  • 提示pipe理员input用户名
  • 删除该用户名的个人资料
    • 还可以删除整个configuration文件 – registryconfiguration单元 (不仅仅是文档和设置中的文件夹结构)。
    • 如果您转到“ 我的电脑”>“属性”>“高级”选项卡>“用户configuration文件设置”,并从中删除configuration文件,也是如此。

有任何想法吗? 所有我能想到的是做一个AD查找来获得指定用户的SID,然后使用它来删除正确的registryconfiguration单元太…更简单的事情会很好,虽然…

基本上,我的服务台曾经是我们的Citrix服务器上的本地pipe理员,对于各种问题的常见修复是为了让他们删除用户在citrix服务器上的configuration文件,让用户重新login,无论他们遇到什么问题解决。 outlook未来,在新的思杰环境中,他们将不再是本地pipe理员,但仍然需要删除configuration文件(删除整个configuration文件:文件夹和registry项是关键)。 谢谢。

如果你正在使用Windows 7或Windows 2008计算机,Powershell会以相当简单的方式执行此操作。

http://techibee.com/powershell/powershell-script-to-delete-windows-user-profiles-on-windows-7windows-2008-r2/1556

我写了这个VB脚本的服务器故障类似的问题。 它将循环访问目标机器上的每个configuration文件,如果要删除configuration文件,则会提示您(逐个)。 它使用WMI Win32_UserProfile来完成这个工作,所以它将被彻底清除。

它会问你目标机器的FQDN。 如果您正在获取权限错误,请更改用户名和密码以反映目标计算机上具有本地pipe理员的帐户。

Option Explicit On Error Resume Next Dim strComputer Dim objWMIService Dim propValue Dim objItem Dim SWBemlocator Dim UserName Dim Password Dim colItems Dim strMessage Dim deleteResponse strComputer = "" UserName = "" Password = "" strMessage = "" strComputer = InputBox("Please enter the FQDN of the new computer:") If strComputer = "" Then WScript.quit End If If Not Ping (strComputer) Then MsgBox "The computer (" + strComputer + ") is not responding to ping - exiting" WScript.quit End if Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator") Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2",UserName,Password) Set colItems = objWMIService.ExecQuery("Select * from Win32_UserProfile",,48) For Each objItem in colItems strMessage = "" If not objItem.LastDownloadTime = "" Then strMessage = strMessage + "LastDownloadTime: " & left(objItem.LastDownloadTime,8) + Chr(10) + Chr(13) End If If Not objItem.LastUploadTime = "" Then strMessage = strMessage + "LastUploadTime: " & left(objItem.LastUploadTime,8) + Chr(10) + Chr(13) End if if not objItem.LastUseTime = "" then strMessage = strMessage + "LastUseTime: " & left(objItem.LastUseTime,8) + Chr(10) + Chr(13) End If If Not objItem.Loaded = "" Then strMessage = strMessage + "Loaded: " & objItem.Loaded + Chr(10) + Chr(13) End If If not objItem.LocalPath = "" then strMessage = strMessage + "LocalPath: " & objItem.LocalPath + Chr(10) + Chr(13) End If if not objItem.RefCount = "" then strMessage = strMessage + "RefCount: " & objItem.RefCount + Chr(10) + Chr(13) End If if not objItem.RoamingConfigured = "" then strMessage = strMessage + "RoamingConfigured: " & objItem.RoamingConfigured + Chr(10) + Chr(13) End If if not objItem.RoamingPath = "" then strMessage = strMessage + "RoamingPath: " & objItem.RoamingPath + Chr(10) + Chr(13) End If if not objItem.RoamingPreference = "" then strMessage = strMessage + "RoamingPreference: " & objItem.RoamingPreference + Chr(10) + Chr(13) End If if not objItem.SID = "" then strMessage = strMessage + "SID: " & objItem.SID + Chr(10) + Chr(13) End If if not objItem.Special = "" then strMessage = strMessage + "Special: " & objItem.Special + Chr(10) + Chr(13) End If if not objItem.Status = "" then strMessage = strMessage + "Status: " & objItem.Status + Chr(10) + Chr(13) End If strMessage = strMessage + Chr(10) + Chr(13) + Chr(10) + Chr(13) + "Do you wish to delete this profile?" deleteResponse = MsgBox (strMessage,35,"Profile Found") Select Case deleteResponse Case 6 Err.Clear objItem.Delete_ If Err.Number = 0 Then MsgBox("Profile " & objitem.localpath & " on " & strComputer & " deleted") Else MsgBox("Profile " & objitem.localpath & " on " & strComputer & " NOT deleted - Is user logged in?") End If End Select Next Function Ping(strHost) dim objPing, objRetStatus set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _ ("select * from Win32_PingStatus where address = '" & strHost & "'") for each objRetStatus in objPing if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then Ping = False else Ping = True end if Next End Function 

它不能使用您详细描述的相同工作stream程(首先请求用户名)。 这种方法的问题是Win32_UserProfile不包含用户名,只有thr SID。 当用户login到机器时,SID用于决定哪个configuration文件是正确的。 这可以防止在AD中重命名用户帐户的问题。

tsprofilecleaner是一个免费的GUI,可以从服务器列表中删除configuration文件: 链接文本

我认为澳大利亚的Cntrl + Alt + Del Consultancy开发了一个可以帮助你的工具。 这就是所谓的REMPROF和这个命令,你可以删除一个服务器的单个configuration文件。 当然,您必须在命令中replace实际的用户名:

 remprof USERNAME 

我不相信你可以从另一台服务器远程运行这个,不幸的是你没有pipe理权限就不能运行它。 我不相信您的支持人员将能够pipe理任何服务器上的用户和用户configuration文件,而无需成为本地pipe理员组的成员。

无论如何,您可以从Cntrl + Alt + Del Consultancy网站下载REMPROF和许多其他有用的工具:

http://www.ctrl-alt-del.com.au/CAD_TSUtils.htm

我希望这有帮助。

艾丽西亚

相反,我们认为没有足够的理由在Citrix服务器上保留任何configuration文件(无论如何,它们都是以任何实际的数据redirect的方式漫游),因此我们设置了在用户注销时删除configuration文件的策略。 感谢所有的build议。

我们使用User Profile Hive Cleanup Service +小脚本,在服务器启动时删除所有USERconfiguration文件。 工作良好

您可以使用delprof或remprof删除configuration文件。 您可以从这些命令创build脚本,也可以使用tsprofcleaner

用户configuration单元位于其用户目录(NTUSER.DAT)下,因此使用rmdir /s /q {username}来删除该目录就足够了。 唯一不会被删除的部分是在registryHKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList的configuration文件列表下,但是所做的只是将SID映射到configuration文件位置。

如果用户login并且该目录不存在,则会再次创build。

不幸的是,没有他们作为pipe理员提升自己,他们将无法删除用户configuration文件。

batch file:

 set /p USERTODEL=Enter the username to delete: set USERTODEL=C:\Users\%USERTODEL% if exist "%USERTODEL%" rmdir /s /q %USERTODEL%