From e2882b8e74b68c167ea7534d410ec717e055e571 Mon Sep 17 00:00:00 2001 From: mrsh Date: Wed, 7 Jan 2026 21:32:42 +0100 Subject: [PATCH] automation md --- ...werShell Automation in Less than 1 Hour.md | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 2.Automation/ Learn PowerShell Automation in Less than 1 Hour.md diff --git a/2.Automation/ Learn PowerShell Automation in Less than 1 Hour.md b/2.Automation/ Learn PowerShell Automation in Less than 1 Hour.md new file mode 100644 index 0000000..fe62af6 --- /dev/null +++ b/2.Automation/ Learn PowerShell Automation in Less than 1 Hour.md @@ -0,0 +1,97 @@ +# Learn Powershell Automation in Less than 1 Hour + +## Schedule-Task + +### Example + +Do a task at a precise time + +```powershell +$trigger = New-ScheduledTaskTrigger -At 3pm -Daily +$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument '-File "C:\Scripts\TestSpace.ps1"' +$settings = New-ScheduledTaskSettingSet + +Register-ScheduledTask ` + -Action $action ` + -Trigger $trigger ` + -TaskName "Test SpaceX" ` + -Description "Tests connection with SpaceX.com" ` + -Settings $settings +``` + +### New-ScheduledTaskTrigger + +Creates a trigger object that defines when the scheduled task will run. + +Breakdown of components + +### New-ScheduledTaskAction + +Defines what program or command the scheduled task will execute. + +### New-ScheduledTaskSettingSet + +Creates a settings object that controls how the task behaves. + +### Register-ScheduleTask + +Registers the task with Windows Task Scheduler, making it active. + + +## Get-ScheduledTask + +Return every Scheduled task + +```powershell +Get-ScheduledTask -TaskName "Test SpaceX" | Get-ScheduledTaskInfo +``` + +## Unregister-ScheduledTask + +Remove a ScheduledTask + +```powershell +Unregister-ScheduledTask -TaskName "Test SpaceX" -Confirm:$false +``` + +## Difference between Scheduled task and schedueld job + +A **scheduled task** is a generic scheduled unit of work, +while a **scheduled job** is a defined, +often reusable execution of that work within a scheduling system. + + +## ScheduledJob + +More advance can run when the computer is in different state (sleep or hibernate) +More straightforward + +### Example + +```powershell +$Trigger = New-JobTrigger -Daily -at 3pm +$Scriptblck = { C:\Scripts\TestSpaceX.ps1 } +Register-ScheduledJob -Name "TestSpaceX Job" -ScriptBlock $scriptblock -Trigger $Trigger +``` + +### Get-ScheduledJob + +List all the ScheduledJob + +```powershell +Get-ScheduledJob -Name "TestSpaceX" | select Name, State +``` + +### Unregister-ScheduledJob + +Remove a ScheduledJob + +```powershell +Unregister-ScheduledJob -Name "TestSpaceX Job" +``` + +## GUI with Powershel + +A graphical user interface application developed using PowerShell to automate tasks, manage systems, and provide user-friendly access to scripts and tools. + +[Disk cleaner example](https://github.com/jimrtyler/diskcleaner/blob/main/DiskCleaner.ps1)