Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

Running job on remote computer as scheduled job

$
0
0

There seems to be times and reasons why running a powershell command or script on a remote computer as a scheduled job is a neccesity. I have been trying to come up with a way to do this on all my servers, most are powershell v2.  I want it to run right away, here I am tying to have it start in 1 minute. 

This is what I have come up with so far, but it doesn't work yet. 

# getservices.ps1 contents:Get-service > C:\services.txt
$computer = "$env:computername"
$command = "powershell.exe -executionpolicy unrestricted -noprofile -file C:\getservices.ps1"
$startTime = (Get-Date).AddMinutes(1)

$sJob = [wmiclass]"\\$computer\root\cimv2:win32_scheduledjob"
$startTime = $sJob.ConvertFromDateTime($startTime)
$errRTN = $sJob.Create($command,$startTime)

 

 

 

 


Viewing all articles
Browse latest Browse all 10624

Trending Articles