【问题标题】:Read mapped drives from user profile location NTUSER.DAT flie从用户配置文件位置 NTUSER.DAT 文件读取映射驱动器
【发布时间】:2021-07-11 04:02:18
【问题描述】:

我想从用户配置文件服务器 NTUSER.DAT 文件中获取映射的网络驱动器信息。你能告诉我从哪里开始吗?我确实在网上找到了一些脚本,但它们没有用。我需要搜索每个配置文件(Reg 加载)并获取网络驱动器信息然后卸载。

任何帮助将不胜感激。

$user = "admin"
$profiles = get-aduser -filter {SamAccountName -eq $user} -properties * 
$sid= $profiles.sid

$profile = " \\serverprofile\drive$\ $user\NTUSER.DAT"

Reg load "HKU\$sid" $profile

Reg export "HKU\$sid\network" "C:\temp\$user\network.reg"

[gc]::collect()
Reg unload "HKU\$sid"

谢谢

【问题讨论】:

  • 1.) 如果查询远程主机,您需要使用凭据进行身份验证,以及 2.) 两个主机可能都需要运行 RemoteRegistry 服务才能使 reg load 成功
  • @Sanny:请在提升模式下打开 Powershell_ise 并执行相同操作。应该没事。 UNC 路径中不应有空格。如果您已正确设置,请检查一下。
  • @metablaster - 1) 用户的配置文件数据 (NTUSER.dat) 位于共享位置服务器上,我有权访问,因此您的意思是我查询的 Jumpbox 上的 RemoteRegistry 服务和应该运行数据所在的配置文件服务器?问题,如果用户已登录,我还能读取注册表中的 NTUSER.dat 文件吗?
  • 我不是 100% 确定 RemoteRegistry,但如果需要,那么是的,它必须在两端运行。据我记得,如果用户已登录,则无法加载 NTUSER.dat,而应使用已加载的 HKU 中现有的配置单元。 (您可以尝试在 HKU 中创建一个新的临时密钥并在那里加载,但如果失败,请不要感到惊讶)
  • the profile data (NTUSER.dat) for users is on a shared location server and I have access 另外我不确定这是否足够,除非该驱动器是在 PS 会话中制作的,请尝试使用 New-PSDrive -PSProvider FileSystem -Credentials 创建临时映射驱动器

标签: powershell powershell-remoting


【解决方案1】:

我不在域上进行测试,但假设您启用了远程处理,请执行以下工作以从 LAN 上的计算机加载配置单元:

$UserName = "USERNAME"
$Domain = "COMPUTERNAME"

$Cred = Get-Credential -Message "Credentials are required to access $Domain"
$CimServer = New-CimSession -ComputerName $Domain -Credential $Cred

$User = Get-CimInstance -ClassName Win32_UserAccount -CimSession $CimServer | Where-Object {
    $_.Name -eq $UserName
} | Select-Object -Property Name, SID

$UserProfile = Get-CimInstance -ClassName Win32_UserProfile -CimSession $CimServer | Where-Object {
    $_.SID -eq $User.SID
} | Select-Object -ExpandProperty LocalPath

$UserProfile = Split-Path -Path $UserProfile -NoQualifier

New-PSDrive -Name Remote -PSProvider FileSystem -Credential $Cred -Root \\$Domain\C$ | Out-Null

$RegKey = "HKU\Remote-$($User.SID)"
$OldLocation = Get-Location

Set-Location Remote:\$UserProfile
reg load $RegKey NTUSER.dat

[gc]::collect()
reg unload $RegKey
Set-Location $OldLocation
Remove-PSDrive -Name Remote

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多