首页 > 解决方案 > 查看最近的远程 powershell 连接

问题描述

在计算机上启动远程 pssession 时是否会生成某种事件日志?我需要能够查看远程会话的来源。

目前我正在跑步

Get-EventLog -LogName "Windows powershell" -newest 100 | Format-List -Property * | where {$_.UserID -eq "username"}

但它没有过滤和/或显示远程连接。

标签: powershellremote-access

解决方案


我们在这里帮助您解决代码问题。这实际上不是代码问题,而是了解如何设置以及在何处关联这些细节。因此,这可能是另一个论坛的问题。

无论如何,为了让您接近您所追求的,您需要采取额外的步骤来获取此类信息。稍后再谈。

现在,一旦您完成所有设置并编写脚本以提取/查看此类信息并且您遇到问题,然后将其发布回此处以供人们查看可以做什么

因此,这将我们引向这里:有三个通用的日志记录区域:

• 模块日志记录 • 脚本块日志记录 • PowerShell 转录

如果您还没有这样做,我建议您启用 PS 审计和脚本日志记录,以便更深入地了解此用例和脚本日志记录(可以捕获在主机上执行的所有命令/代码)。如果您正确设置了所有这些,您首先查看脚本日志以获取详细信息,并查看您在帖子中引用的日志名称以获取其他详细信息。

通过 GPO 或 DSC 设置此企业范围。

有很多关于如何设置的指导。

例如:

使用转录和日志记录审核 PowerShell 使用情况

Get-Command -Name '*transcript*'

CommandType Name                        Version   Source
----------- ----                        -------   ------
Cmdlet      Get-TRSTranscriptionJob     3.3.234.0 AWSPowerShell
Cmdlet      Get-TRSTranscriptionJobList 3.3.234.0 AWSPowerShell
Cmdlet      Start-Transcript            3.0.0.0   Microsoft.PowerShell.Host
Cmdlet      Start-TRSTranscriptionJob   3.3.234.0 AWSPowerShell
Cmdlet      Stop-Transcript             3.0.0.0   Microsoft.PowerShell.Host

https://docs.microsoft.com/en-us/powershell/wmf/5.0/audit_overview

实用的 PowerShell 安全性:使用 DSC 启用审计和日志记录

https://blogs.technet.microsoft.com/ashleymcglone/2017/03/29/practical-powershell-security-enable-auditing-and-logging-with-dsc

PowerShell V5 中的更多新内容:额外的 PowerShell 审计

Get-Module Microsoft.* | Select Name, LogPipelineExecutionDetails
Get-Module Microsoft.* | ForEach {     $_.LogPipelineExecutionDetails = $True }
(Import-Module ActiveDirectory).LogPipelineExecutionDetails = $True
Get-WinEvent -FilterHashtable @{LogName='Windows PowerShell';Id ='800'} -MaxEvents 1 | Select -Expand Message

https://learn-powershell.net/2014/08/26/more-new-stuff-in-powershell-v5-extra-powershell-auditing

调查 PowerShell:命令和脚本日志记录

https://www.crowdstrike.com/blog/investigating-powershell-command-and-script-logging


推荐阅读