PowerShell script with parameters in scheduled task:
Say, We've a Parameter "$WebAppURL" in our PowerShell script:
Param(
[parameter(Mandatory=$true)] $WebAppURL
)
# We'll trigger the script as: .\StorageReport "http://sharepoint.crescent. com"
So in Task scheduler, Add arguments(optional), Enter: d:\scripts\StorageReport "http://sharepoint.crescent. com"
When there are multiple parameters, you can separate them by giving parameter name as key. such as:
Param(
[parameter(Mandatory=$true)] $WebAppURL,
[parameter(Mandatory=$true)] $OutPut
)
# We trigger it as: StorageReport -WebAppURL "http://sharepoint.crescent. com" -output "d:\Reports\StorageReport.csv"
Say, We've a Parameter "$WebAppURL" in our PowerShell script:
Param(
[parameter(Mandatory=$true)] $WebAppURL
)
# We'll trigger the script as: .\StorageReport "http://sharepoint.crescent.
So in Task scheduler, Add arguments(optional), Enter: d:\scripts\StorageReport "http://sharepoint.crescent.
When there are multiple parameters, you can separate them by giving parameter name as key. such as:
Param(
[parameter(Mandatory=$true)] $WebAppURL,
[parameter(Mandatory=$true)] $OutPut
)
# We trigger it as: StorageReport -WebAppURL "http://sharepoint.crescent.
Create Scheduled Tasks with PowerShell:
From PowerShell 3.0 (Windows Server 2012 R2) onwards , We've a new cmdlets to create and manage Scheduled Tasks! Here is an example:
1
2
3
4
5
6
7
8
9
10
11
| #Variables $TaskName = "Audit Large Lists" $username = "Crescent\SP13_FarmAdmin" $password = "Password Here" #Create Scheduled Task $Action = New -ScheduledTaskAction -Execute "PowerShell.exe" -Argument "E:\Scripts\AuditLists.ps1" $Trigger = New -ScheduledTaskTrigger -Daily -At 1am $ScheduledTask = New -ScheduledTask -Action $action -Trigger $trigger Register -ScheduledTask -TaskName $TaskName -InputObject $ScheduledTask -User $username -Password $password |
No comments:
Post a Comment