In last week’s PowerShell class, we had a question about not only running a scheduled job, but how to unregister it after it finishes. Good question. The answer is actually very simple. The code below is a very simple job. The problem with it is that after it executes, it will stay in memory until you unregister it. $Trigger = New-ScheduledTaskTrigger -Once -At ( Get-Date ) . AddMinutes( 1 ) Register-ScheduledJob -Trigger $Trigger ` -Name "Test1" ` -ScriptBlock { Get-CimInstance -ClassName Win32_Bios } In the Task Scheduler, we can see that the job completed, but it still in memory. The cmdlet Unregister-ScheduledJob must be run to remove this object from memory. PS C:\> Unregister-ScheduledJob -Name Test1 Now we will re-code the script to automatically remove the job after it completes. $Trigger = New-ScheduledTaskTrigger -Once -At ( Get-Date ) . AddMinutes( 1 ) Re
Welcome to the blogsite of MCTExpert. I am a Microsoft Certified Trainer. Here you will find the real questions that are asked to me by my students.