0

I installed the PS Scripts on my virtaul machine. My VM is connected to a domain account i have one service account provided. Right now my script is running manually. But when im waiting for the time that ive set the script it doesnt work. Im using Windows server 2016.

Power Shell Script

$path = "C:\Users\svaccount\Desktop\STAT1\"
$fileName = "STAT1_"
$date = Get-Date -Format MMddyyyhhmmss 
$file = $path + $filename +
$date + ".jpeg"  
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
# Create bitmap using the top-left and bottom-right bounds 
$bitmap = New-Object System.Drawing.Bitmap $Width, $Height
# Create Graphics object 
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
# Capture screen 
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
# Save to file 
$bitmap.Save($File)

My Configuration in Task.

GENERAL TAB
-security options
   .account user: (service account)
   .I select Run Only when user is logged on
   .Selected run with highest privileges
   .configure for: windows server 2016

TRIGGER TAB
Begin the task: on a Schedule
Settings: Daily, Recur every 1 days
Adv Settings: selected Repeat task every: 5 min for a duration of 1 ay
ENABLE is selected

ACTION TAB
action: start a program
Settings: 
   .Program/script: powershell.exe
   .add arguments(optional): -windowstyle hidden "C:\POGI.ps1"

CONDITIONS TAB
   .Selected wake the computer to run this task

SETTINGS TAB
    .Selected allow task to be run on demand

I find a line to debug my script: i dont know if this helps

**********************
Windows PowerShell transcript start
Start time: 20181129151208
Username: OSISOFT\svaccount
RunAs User: OSISOFT\svaccount
Machine: PI-WBS (Microsoft Windows NT 10.0.14393.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 19732
PSVersion: 5.1.14393.206
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14393.206
BuildVersion: 10.0.14393.206
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is c:\temp\debug.log
**********************
Windows PowerShell transcript end
End time: 20181129151209
**********************

Appreciate your help with this

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.