【问题标题】:How to take a remote screenshot with Powershell如何使用 Powershell 远程截屏
【发布时间】:2020-01-31 01:44:04
【问题描述】:

我正试图弄清楚如何通过 PowerShell 从 AD 服务器上的管理员帐户到网络上的任何计算机进行远程屏幕截图。

到目前为止,我得到了以下内容。

 $ComputerName = '<THECOMPUTER>'

 copy-item "C:\Public\Software\Take-Screenshot.ps1" "\\$ComputerName\C$\"

 Invoke-Command -ComputerName $ComputerName -ScriptBlock {
     powershell -nop -c "C:\Take-Screenshot.ps1"
 } 

Take-Screenshot.ps1 来自here,但我已将以下内容添加到脚本底部以实际运行该函数。

Take-ScreenShot -screen -file C:\s.png -imagetype png 

截图后我会复制回宿主,但问题是图片全黑。

我在想这可能是因为powershell正在运行程序,但没有附加会话,所以真的没有屏幕??

【问题讨论】:

标签: powershell active-directory screen-capture


【解决方案1】:

所以我得到了这个工作,但它有点涉及。适用于多台显示器。

您需要远程 PC 上的Screenshot.ps1、本地 PC (Google) 上的触发脚本和 PSExec。

# This is Screenshot.ps1
# Add types and variables
$File = "C:\Temp\Screenshot1.bmp"
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing

# Gather Screen resolution information
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width = $Screen.Width
$Height = $Screen.Height
$Left = $Screen.Left
$Top = $Screen.Top

# Set bounds
$bitmap = New-Object System.Drawing.Bitmap $Width, $Height

# Create Object
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)

# Capture
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)

# Save
$bitmap.Save($File)

然后是触发脚本

#Setup Variables
$ComputerName = "ComputerName"
$PSExec = "C:\temp\tools\psexec.exe"

# Captures session details
$quser = (((query user /server:$ComputerName) -replace '^>', '') -replace '\s{2,}', ',' | ConvertFrom-Csv)

# Takes screenshot of remote PC
&$PSExec -s -i $quser.ID "\\$ComputerName\" PowerShell -WindowStyle Hidden -File "C:\Temp\screenshot.ps1"

【讨论】:

  • 这是完美的。在我意识到它需要附加到会话之后,我实际上开始使用 psexec,但是我的尝试效果不佳。添加了一些代码来选择特定用户并将screenshot.ps1传输到机器上,否则这正是我想要的!
  • 我确实注意到,当 PSExec 运行时,屏幕上会出现一个黑框闪烁几分之一秒,即使 -WindowStyleHidden 有什么办法没有吗?
  • 可能有点晚了——要摆脱黑匣子,你需要从已经不可见的东西启动 ps1,比如 vbs 文件
猜你喜欢
  • 1970-01-01
  • 2021-06-28
  • 1970-01-01
  • 1970-01-01
  • 2018-11-21
  • 2012-05-05
  • 2013-07-31
  • 2012-10-22
  • 1970-01-01
相关资源
最近更新 更多