运行 远程获取当前用户注册码的 powershell 脚本?
Running powershell script to get the currentuser regkey remotely?
所以我无法从当前用户注册码远程获取一些注册码信息。我不知道我做错了什么我可以在我的机器上提取这些信息,但不能远程提取。任何输入都会有所帮助,谢谢。
$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 Run the program so that it interacts with the desktop of the
specified session on the remote system. If no session is specified the
process runs in the console session.
-u Specifies optional user name for login to remote computer.
有一个 PowerShell 模块,通过 MS powershellgallery.com
利用了 psexec 方法
使用 WMF 5 及更高版本(以获取可用的最新 InvokePsExec 模块版本),只需 运行 此命令(需要互联网连接):
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
综上所述,要获取远程注册码,您无需尝试 运行 当前用户的任何操作,只需点击注册表配置单元并拉取它,就像在本地操作一样.
此外,无需从头开始执行此操作,因为使用 'PowerShell hkcu remotely' 进行快速网络搜索将为您提供一份很好的尝试此方法的人员名单以及他们的结果。
这里是一个结果示例,展示了如何使用遗留模块挖掘远程注册表。
### 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
}
}
所以我无法从当前用户注册码远程获取一些注册码信息。我不知道我做错了什么我可以在我的机器上提取这些信息,但不能远程提取。任何输入都会有所帮助,谢谢。
$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 Run the program so that it interacts with the desktop of the specified session on the remote system. If no session is specified the process runs in the console session.
-u Specifies optional user name for login to remote computer.
有一个 PowerShell 模块,通过 MS powershellgallery.com
利用了 psexec 方法使用 WMF 5 及更高版本(以获取可用的最新 InvokePsExec 模块版本),只需 运行 此命令(需要互联网连接):
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
综上所述,要获取远程注册码,您无需尝试 运行 当前用户的任何操作,只需点击注册表配置单元并拉取它,就像在本地操作一样.
此外,无需从头开始执行此操作,因为使用 'PowerShell hkcu remotely' 进行快速网络搜索将为您提供一份很好的尝试此方法的人员名单以及他们的结果。
这里是一个结果示例,展示了如何使用遗留模块挖掘远程注册表。
### 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
}
}