Last active
July 9, 2019 07:42
-
-
Save zbalkan/b099f52fdac6626ef2dc7480626df8c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function New-RemoteScheduledTask { | |
[CmdletBinding()] | |
param ( | |
# Hostname to create the task on | |
[string] | |
$Hostname, | |
# Credentials for connecting to the host | |
[System.Management.Automation.PSCredential] | |
$Credential, | |
# Task Name | |
[string] | |
$Name, | |
# Task Description (optional) | |
[string] | |
$Description, | |
# Scheduled task action | |
[CimInstance] | |
$Action, | |
# Scheduled task trigger | |
[CimInstance] | |
$Trigger, | |
# Scheduled task principal | |
[CimInstance] | |
$Principal | |
) | |
process { | |
Invoke-Command -ComputerName $Hostname -Credential $Credential -ScriptBlock { | |
Register-ScheduledTask -Action $Action -Trigger $Trigger -Principal $Principal -TaskName $Name -Description $Description | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage:
It does not test the hostname and credentials before execution.