从PowerShell刷新远程Windows服务器用户配置文件

时间:2016-09-13 22:56:50

标签: powershell powershell-v2.0 powershell-v3.0 powershell-remoting

我正在开展一个项目,我需要每晚在许多机器上刷新特定的用户个人资料。留下证据表明刷新已经完成是有帮助的。因此,我的手动过程是重命名文档和设置文件夹并删除用户注册表项。

我正在尝试从powershell编写脚本,我可以在其中重命名远程用户文件夹,但无法删除注册表项。到目前为止,我试图从远程服务器上删除我的本地sid。

我可以识别并删除所需的远程sid吗?

[array] $Computers =  "computer2", "computer1", "computer3"
ForEach ($computer in $Computers) { 
#rename the folder
$source = "\\$computer\c$\Documents and Settings\theUser"
$dest = "\\$computer\c$\Documents and Settings\theUser.old"
Rename-Item -path $source -newname $dest -force
#delete the SID
$objUser = New-Object System.Security.Principal.NTAccount("theUser")
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
REG DELETE "\\$computer\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$strSID"
}

0 个答案:

没有答案