PowerShell : AT Commands Module

23/10/2011

2 comments

AT Command is an old DOS external command (not included in command.com) which enables users to schedule tasks on local/remote computer. You can use the AT command to schedule a command, a script, or a program to run at a specified date and time. You can also use this command to view existing scheduled tasks (Only AT Tasks).

image

 

Differences between OS versions

  • Task scheduler in Vista and above needs to be refreshed in order to display new tasks, whereas in windows XP the refresh is automatically
  • In Vista and above tasks are not deleted after expiration
  • Dated tasks, in Vista and above Runs Repeatedly. Task in Windows XP can set to run once in a specific date.
  • In Vista and above Tasks cannot run Interactively,I suppose Microsoft excluded this option for security reasons.

 

Prerequisites

To use AT Command, the Task Scheduler service must be running. and you must be logged on as a member of the local Administrators group (on local and remote machine)

PowerShell Module PowerShell version 2 doesn’t include scheduled task cmdlets, so I wrote my own module which includes three advanced functions: New-AtTask, Get-AtTask and Remove-AtTask.

נורת חשמלPowerShell version 3 includes many new and improved cmdlets, among them ‘Scheduled Job’ and ‘Scheduled task’ modules (Supported Operating Systems: Windows 7 Service Pack 1, Windows Server 2008 R2 SP1). You can download PowerShell version 3 CTP1 from HERE .

New-AtTask

Enables an administrator to create scheduled AT tasks on a local or remote system.

Tasks can be configured to run at a specific date or time, and can be specified to run repeatedly. You can schedule a task to run at selected days of the week or month.

If the InteractWithDesktop switch is specified, the job would be interactive (only on XP and lower versions).

C:\PS> Get-help New-ATTask –Full 

Gets cmdlet full help

image

 

C:\PS> New-ATTask -Command “ipconfig /flushdns” -Time 11:40
    
Create a new AT Task on Remote computer, to flush dns cache at 11:40, Run only once

image

Capture

 

C:\PS> New-ATTask –Command “Cmd /c GPUpdate.exe” -Time 11:50 -ComputerName server1,server2,server3 -DayOfWeek Sunday,Thursday –RunRepeatedly

– OR-

C:\PS> “server1″,”server2″,”server3” | New-ATTask –Command “Cmd /c GPUpdate.exe” -Time 11:50 -DayOfWeek Sunday,Thursday –RunRepeatedly

Create new AT Task on server1,server2 and server3, to run GPUpdate at 11:50 next Sunday & next Thursday, every week

image

 

C:\PS> Get-Content d:\Computers.txt | Get-ATTask

Read computer list from Computers.txt file and Get AT Task list from each of them

 

Get-AtTask

Enables an administrator to get scheduled AT tasks from a local or remote systems.

C:\PS> Get-help Get-ATTask –Full 

Gets CmdLet full help

 

C:\PS> Get-ATTask

Get AT Task list from local computer (only AT tasks).

image

 

C:\PS> “Server1″,”Server2” | Get-ATTask | Format-Table

-OR-

C:\PS> Get-ATTask –ComputerName Server1,Server2 | Format-Table

image

 

Remove-AtTask

 Enables an administrator to remove scheduled AT tasks from a local or remote system.

C:\PS> Get-help Remove-ATTask –Full 

Gets CmdLet full help

 

C:\PS> Remove-ATTask -JobID 2 -ComputerName Server1

Remove AT job number 2  from remote computer Server1, only if you are sure חיוך קורץ

image

נורת חשמל To avoid confirmation write the following command:

C:\PS> Remove-ATTask -JobID 2 -Confirm:$false

C:\PS> Get-ATTask -ComputerName Server1,Server2 | Where-Object {$_.Command -eq ‘ipconfig /renew’} | Remove-ATTask -WhatIf

The above example shows what would have happen if the actual command would have run. It gets the AT Task list from Server1 and Server2 and filters jobs which have the ‘ipconfig /renew’ command.

נורת חשמלRemove the WhatIf switch to actually run the command.

 

How to use

  1. Download and run the setup file
  2. Load the module – Import-Module ATCommands

image

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

2 comments

  1. Bob27/10/2011 ב 12:45

    There is a TaskScheduler module in the Powershell Pack
    http://archive.msdn.microsoft.com/PowerShellPack.

    Re. “Tasks cannot be run interactively”, perhaps not via AT but they can using SCHTasks or created via the GUI.

    Reply