使用powershell加载ntuser.dat

时间:2012-06-13 11:00:49

标签: powershell registry

我需要检查网络中Windows客户端上所有用户的一些设置。所有用户都有漫游配置文件。

我编写了一个Powershell脚本,用于加载用户NTuser.dat的脱机副本并读出特定的密钥。然后卸载该文件,并将下一个文件加载到注册表中。

问题是大约10个用户后没有加载新文件。再次启动脚本时,用户仍然无法加载。新用户只有在我关闭Powershell提示并打开一个新用户之后。脚本总是在大约10个用户之后停止。

$userlist = ls "C:\Temp calls\profiles"
foreach ($user in $userlist){
$username = $user.name
#$username = "ciproda"
reg load "hklm\$username" "C:\Temp calls\profiles\$username\NTUSER.DAT" | Out-Null
...

    Here I check the keys

    ...

[gc]::collect()
start-sleep -s 3
reg unload "hklm\$username"
}

1 个答案:

答案 0 :(得分:2)

在“此处检查按键”部分中,您是使用以下内容将hive安装为PS驱动器:

new-Psdrive -name <blah> -PSProvider Registry -root <blih>
cd <blah>:
# Some Set-ItemProperty and Get-ItemProperty calls here referring to
# your PSDrive and using PowerShell variables
Remove-PSDrive <blah>

如果在调用REG UNLOAD之前仍然引用了某些PSDrive变量,则该调用可能会失败。尝试通过Remove-Variable删除所有仍然引用您的PSDrive的变量。