hot to make cyclic execution into powershell

Ilya Bokov 125 Reputation points
2024-01-09T09:54:37.41+00:00

hi! how a can make cyclic execution into powershell script to add it on domain computers, and start by user logon, and every 3sec. may be someone have another script.

$Path = "C:\ps\screenshots"

# Проверяем, что каталог для хранения скриншотов создан, если нет - создаем его

If (!(test-path $path)) {

    New-Item -ItemType Directory -Force -Path $path

}

Add-Type -AssemblyName System.Windows.Forms

$screen = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds

# Получаем разрешение экрана

$image = New-Object System.Drawing.Bitmap($screen.Width, $screen.Height)

# Создаем графический объект

$graphic = [System.Drawing.Graphics]::FromImage($image)

$point = New-Object System.Drawing.Point(0, 0)

$graphic.CopyFromScreen($point, $point, $image.Size);

$cursorBounds = New-Object System.Drawing.Rectangle([System.Windows.Forms.Cursor]::Position, [System.Windows.Forms.Cursor]::Current.Size)

# Получаем скриншот экрана 

[System.Windows.Forms.Cursors]::Default.Draw($graphic, $cursorBounds)

$screen_file = "$Path\" + $env:computername + "_" + $env:username + "_" + "$((get-date).tostring('yyyy.MM.dd-HH.mm.ss')).png"

# Сохранить скриншот в файл

$image.Save($screen_file, [System.Drawing.Imaging.ImageFormat]::Png)


Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,516 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,149 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
525 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,465 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,446 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,596 Reputation points
    2024-01-09T15:54:02.6233333+00:00

    In order to take a screenshot from a scheduled task the scheduled task would have to run only when the user was logged on and would have to be run by the user. Without a desktop (as would be the case if the scheduled task were run using, say, the System account) there's no screen to capture.

    You might find these useful:

    https://stackoverflow.com/questions/2969321/how-can-i-do-a-screen-capture-in-windows-powershell

    https://stackoverflow.com/questions/57140437/automated-screenshots-using-powershell-and-task-scheduler

    There are plenty of other question and answers to be found with a search like "powershell take a screen shot from scheduled task".


0 additional answers

Sort by: Most helpful