Examples/Resources/ScheduledTask/10-RunPowerShellTaskOnceAsUserInteractiveOnly.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<#
    .EXAMPLE
    This example creates a scheduled task called 'Test task interactive' in the folder
    task folder 'MyTasks' that starts a new powershell process once. The task will
    execute using the credential passed into the $Credential parameter, but only when
    the user contained in the $Credential is logged on.
#>

Configuration Example
{
    param
    (
        [Parameter()]
        [System.String[]]
        $NodeName = 'localhost',

        [Parameter(Mandatory = $true)]
        [ValidateNotNullorEmpty()]
        [System.Management.Automation.PSCredential]
        $Credential
    )

    Import-DscResource -ModuleName ComputerManagementDsc

    Node $NodeName
    {
        ScheduledTask MaintenanceScriptExample
        {
            TaskName            = 'Test task Interactive'
            TaskPath            = '\MyTasks'
            ActionExecutable    = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe'
            ScheduleType        = 'Once'
            ActionWorkingPath   = (Get-Location).Path
            Enable              = $true
            ExecuteAsCredential = $Credential
            LogonType           = 'Interactive'
        }
    }
}