Dictionaries/Dict.Windows/Dict.Windows.psm1
<# ######## ### ###### ## ## ###### ###### ## ## ######## ######## ## ## ## ######## ######## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ###### ##### ###### ## ######### ###### ## ## ## ## ## ###### ######## ## ######### ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ###### ## ## ###### ###### ## ## ######## ######## ####### ######## ######## ## ## #> <# .SYNOPSIS Create a new folder in the Operating System's task scheduler .DESCRIPTION Create a new folder in the Operating System's task scheduler daemon. .PARAMETER FolderName The name of the folder to create .PARAMETER Root An optional root folder to be the parent of the folder to create .EXAMPLE New-ScheduledTaskFolder -FolderName "MyDaemon" .NOTES On linux, this function just create an empty file under /etc/cron.d by default #> function New-ScheduledTaskFolder { [CmdletBinding()] [OutputType([Boolean])] [Alias('New-CronTaskFile')] Param ( [Alias('Name')] [Parameter(Mandatory = $true, ValueFromPipeLine = $true)][string]$FolderName, [string]$Root = '\' ) Begin { Write-EnterFunction } Process { $ErrorActionPreference = "stop" $scheduleObject = New-Object -ComObject schedule.service $scheduleObject.connect() $rootFolder = $scheduleObject.GetFolder($Root) Try { $null = $scheduleObject.GetFolder($FolderName) } Catch { $null = $rootFolder.CreateFolder($FolderName) } Finally { $ErrorActionPreference = "continue" } # test to return correct value Try { $null = $scheduleObject.GetFolder($FolderName) return $true } Catch { return $false } } End { Write-LeaveFunction } } |