如何使用Powershell拍摄远程屏幕截图

问题描述 投票:1回答:1

我试图弄清楚如何通过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个回答
0
投票

所以我让它起作用了,但是有点累。适用于多台显示器。

您将需要Screenshot.ps1,您的触发脚本和PSExec(Google)。

# 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"
© www.soinside.com 2019 - 2024. All rights reserved.