А АFriday, 5 August 2016

Make screenshot by PowerShell.

Hello everybody.

I need visual control to one interesting software complex. Due to security policy I can't use RDS or any similar tools. But I have to watch the main window of this complex every half an hour. It's not comfortable for me and my colleagues. What do you advice me? Thanks, while you think or write me advice I decided to make the following.

I decided to use PowerShell for grabbing screen of complex monitor and send result to my e-mail. I took some PS-code from here https://www.sysadmins.lv/blog-ru/delaem-skrinshoty-sredstvami-powershell.aspx.

If you need details about creation Jpeg-file so you can read description by each strings there. And in second part I added my PS-code for sending this file via smtp-server.

So, my PS-code is below:

#1 ARM screen grabbing
Add-Type -AssemblyName System.Windows.Forms
$screenBounds = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
$image = New-Object System.Drawing.Bitmap($screenBounds.Width, $screenBounds.Height)
$g = [System.Drawing.Graphics]::FromImage($image)
$p = New-Object System.Drawing.Point(0, 0)
$g.CopyFromScreen($p, $p, $image.Size);

#2 send screenshot to my e-mail
$smtpServer = "SmtpServerName"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Port = 25

$compname = Get-Content env:computername
$att = New-object Net.Mail.Attachment("$dir\arm.jpg")

$msg.From = "my-email@compnyc.com"
$msg.subject = "ARM $compname notification"
$msg.body = "attached ARM screenshot"

It's clear. It's easy.
Good luck.

1 comment:

Anonymous said...

My profile is included only two strings:
filter Get-TypeName {if ($_ -eq $null) {''} else {$_.GetType().Fullname }}

I have to see current version of PS and online filter for GetTypeName of any PS's object.

Post a Comment

А что вы думаете по этому поводу?

Версия на печать


Медиа облако