Hi. I’m new to PS. I’m trying to run this script which will launch an application in a server, take a screenshot and send an email. I can RDP in to the server and run the script and it would work. But i would like to run this automatically using task scheduler or something to run it every 5/6 hours(I know its a dumb question, as background processes in windows don’t work that way). Below is something that im trying to run. Any idea that can lead me to the correct path would be greatly appreciated. I’m hoping this can be done without any third party tool, not that i cant
start-process "PATH TO AN APPLICATION.EXE" Start-Sleep -Milliseconds 1000 $File = ".\SCREENSHOT.bmp" Add-Type -AssemblyName System.Windows.Forms Add-type -AssemblyName System.Drawing $Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen $Width = $Screen.Width $Height = $Screen.Height $Left = $Screen.Left $Top = $Screen.Top $bitmap = New-Object System.Drawing.Bitmap $Width, $Height $graphic = [System.Drawing.Graphics]::FromImage($bitmap) $graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size) $bitmap.Save($File) Write-Output $File $SendTo = "sENDTO" $SMTPServer = "smtp" $EmailFrom = “ABC@ABC.COM” $EmailSubject = “SCREENSHOT” $Image = ".\SCREENSHOT.bmp" $Message = new-object Net.Mail.MailMessage Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue $attachment = new-object Net.Mail.Attachment($Image) $attachment.ContentId = "att" $smtp = new-object Net.Mail.SmtpClient($smtpServer) $body = '' $Message.From = $EmailFrom $Message.To.Add($SendTo) $Message.Subject = $EmailSubject $Message.Body = $body $Message.IsBodyHTML = $true $Message.Attachments.Add($att) $smtp.Send($Message) $attachment.Dispose()