因此,我无法从当前用户的注册表项中远程获取某些注册表项信息。我无法弄清楚我在做什么错,我可以在机器上提取此信息,但不能远程获取。任何输入都会有所帮助,谢谢。
$session = New-PSSession -ComputerName $ComputerName
Invoke-Command -Session $session {$hotfix = Get-HotFix;
$Reg = [Microsoft.Win32.RegistryKey]::OpenBaseKey('CurrentUser','default');
$RegKey= $Reg.OpenSubKey("SOFTWARE\\Google\\Chrome\\BLBeacon");
$ChromeBuild = $RegKey.GetValue("VERSION");
return $ChromeBuild, $hotfix}
PowerShell将始终在启动它的用户的上下文中运行。
您不能使用PowerShell以当前用户的远程登录身份运行,因为这是Windows安全边界。
要以登录用户的身份运行代码,请创建一个计划任务,该任务将在用户登录时运行,或者使用MS SysteInternals psexec.exe(它提供了以登录用户身份运行的参数。)>
根据文档...
psexec -i运行程序,使其与桌面的交互在远程系统上指定的会话。如果未指定会话,则进程在控制台会话中运行。
-u指定用于登录到远程计算机的可选用户名。
有一个PowerShell模块,通过MS powershellgallery.com来利用psexec方法。
使用WMF 5及更高版本(以获取最新的InvokePsExec模块版本),只需运行此命令(需要Internet连接:]
Find-Module -Name '*psexec*' | Format-Table -AutoSize <# Version Name Repository Description ------- ---- ---------- ----------- 0.0.7 psexec PSGallery A small PowerShell module to run Sysinternals PsExec 1.2 InvokePsExec PSGallery Svendsen Tech's Invoke-PsExec for PowerShell is a function that lets you execute PowerShell and batch/cmd.exe code asynchro... #> Install-Module -Name InvokePsExec
话虽这么说,要获得远程regkey,您不需要像当前用户一样尝试运行任何东西,只需像在本地一样,按下注册表配置单元并拉出它即可。
[此外,也无需从头开始,因为使用'PowerShell hkcu进行快速的网络搜索将为您提供一个很好的尝试此方法的人及其结果列表。
这里是一个结果示例,显示了如何使用旧版模块挖掘远程注册表。
### query HKCU registry information remotely
<#
https://community.idera.com/database-tools/powershell/ask_the_experts/f/powershell_remoting-24/17743/query-hkcu-registry-information-remotely
Please check the below posted script. It requires get-regstring module. Its available in http://psremoteregistry.codeplex.com/
I used this script successfully to find a entry in proxyoverride settings of a each logged in user. You can change this script as per your need.
#>
$computer = Get-Content 'c:\test\hosts.txt '
Foreach ($comp in $computer)
{
$name = Get-WmiBbject Win32_ComputerSystem -computername $comp |
select username
$namesplit = $name.username.split('\')
$domainname = $namesplit[0]
$Username = $namesplit[1]
$objUser = New-Object System.Security.Principal.NTAccount("$domainname","$username")
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$SID = $strSID.Value
$getRegStringSplat = @{
Key = "$SID\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Hive = 'users'
ComputerName = $comp
Value = 'proxyoverride'
}
$reg = Get-RegString @getRegStringSplat
$regoutput = $reg |
Select data
$searchstr = "somedomain.com"
$Sel = $regoutput |
Select-String $searchstr -SimpleMatch
If ($sel -eq $null)
{
"In $comp $username does not contain $searchstr." |
Out-file c:\test\proxy_output.txt -Append
}
Else
{
"Somedomain.com Found in $comp in $username" |
Out-file c:\test\proxy_output.txt -Append
}
}