Tag Archives: Get-ScheduledTask

New versions of scripts and a new script in the TechNet Script Gallery

After attending the PowerShell Conference Asia this weekend in Singapore I realized I did not update my scripts in the TechNet Script Gallery for a while, so I took some time to go through the feedback and feature requests for my scripts. I found out that there was some work to be done on a number of my scripts and I got started with it.

First of all I started with the The Get-ScheduledTask script, I added in the ComputerName from which the tasks are gathered in the output. This was done to ensure that the script functions as expected when used in combination with the Remove-ScheduledTask script. Additionally I also included the triggers in the output as requested by Profile787.

Get-ScheduledTask

The Remove-ScheduledTask script is able to remove scheduled tasks and supports pipeline input from the Get-ScheduledTask script:

.EXAMPLE 
Remove-ScheduledTask -ComputerName JaapTest01 -Path '\Folder\YourTask' 
 
Description 
----------- 
Will remove the YourTask task from the JaapTest01 system 
 
.EXAMPLE 
.\Get-ScheduledTask.ps1 | Where-Object {$_.State -eq 'Disabled'} | Remove-ScheduledTask -WhatIf 
 
Description 
----------- 
Get-ScheduledTask will list all the disabled tasks on a system and the Remove-ScheduledTask function will list all the actions that could be taken

Get-OrphanHomeFolder, there were two requests for new functionality and because of that I introduced two new parameters:

  • SearchBase
  • CheckHomeDirectory
.PARAMETER SearchBase
This parameter determines what the SearchBase for the AD query is, the LDAP path for an OU should be specified here. This can be used to limit the AD Query to a sub tree within Active Directory

.PARAMETER CheckHomeDirectory
Setting this switch parameter will check the full path of the folder against the HomeDirectory attribute of an ADObject, when using this switch make sure that the correct shared folder or DFS path is used, otherwise output can be unreliable

.EXAMPLE 
.\Get-OrphanHomeFolder.ps1 -HomeFolderPath \\Server01\Home -SearchBase 'LDAP://OU=YourOU,DC=jaapbrasser,DC=com'

Description:
Will list all the folders in the \\Server01\Home path. For each of these folders it will query AD, only in the YourOU Organizational Unit of the JaapBrasser domain, using the foldername

.EXAMPLE 
.\Get-OrphanHomeFolder.ps1 -HomeFolderPath \\dfs\share\userfolders\ -CheckHomeDirectory

Description:
Will list all the folders in the \\Server02\Fileshare\Home folder and check against the homedirectory attribute of the AD objects

The Get-UnchangedPwdlastset script has also been updated, as one of the default values was being added instead of subtracted from the result as noted by Richard Mueller.Finally the last script that has been updated is the Get-LoggedOnUser script. Apaladi correctly noted that with certain regional datetime settings it would be possible for the script to truncate the data incorrectly.

For more information or the direct download links of these scripts please refer to the links below. Feel free to leave a comment either here or in the TechNet Script Library.

TechNet Script Gallery
My entries in TechNet Script Gallery
Get scheduled tasks from remote computer
Remove Scheduled Tasks from remote computer
Script to get orphaned home folders and folder size
Query for AD Users that have not changed password for x-days
Get-LoggedOnUser Gathers information of logged on users on remote systems

New script Remove-ScheduledTask in TechNet Script Gallery

One of the things that keeps me busy is maintaining the library of scripts I have made available in the TechNet Script Library. Earlier this week I noticed a request for my Get-ScheduledTask script, a script that gets a list containing the scheduled tasks from either the local machine or a remote system. The request stated if it was possible to create a function that could delete scheduled tasks.

Based on this question I had a look at the Get-ScheduledTask script and decided that it requried an additional property in the custom object that it outputs, the computer name. Using both the computer name and the path of a scheduled task I am able to delete scheduled tasks on both local systems as well as remotely.

Here is an example of Remove-ScheduledTask in combination with Get-ScheduledTask:

Get-ScheduledTask-Remove

.EXAMPLE
.\Get-ScheduledTask.ps1 | Where-Object {$_.State -eq 'Disabled'} | Remove-ScheduledTask -WhatIf

Description
-----------
Get-ScheduledTask will list all the disabled tasks on a system and the Remove-ScheduledTask function will list all the actions that could be taken

For more information or the direct download links of these scripts please refer to the links below. Feel free to leave a comment either here or in the TechNet Script Library.

TechNet Script Gallery
My entries in TechNet Script Gallery
Get-ScheduledTask
Remove-ScheduledTask

 

New article on PowerShell Magazine: Retrieve scheduled tasks using Schedule.Service COMObject

My new tip has been posted on PowerShell Magazine is on how to retrieve scheduled tasks using Schedule.Service Com Object using PowerShell. Using this object it is possible to retrieve information about scheduled tasks either on the local or remote system. The full article containing tips on how to use this com object and what the considerations are when using this object is available on PowerShell Magazine : Retrieve scheduled tasks using Schedule.Service COMObject

The following code will connect to the local system using the Schedule.Service Com Object, administrative permissions are required to run this code:

$Schedule = New-Object -ComObject "Schedule.Service"
$Schedule.Connect('localhost')
$Folder = $Schedule.GetFolder('\')
$Folder.GetTasks(1) | Select Name,Path,State

For more articles like this, have a look at the External Articles section of my blog, it contains all the articles I have posted on external sources such as PowerShell Magazine. The article posted on PowerShell magazine contains a link to my Get-ScheduledTask script in the TechNet Script Gallery.

Links in this Article
PSTip: Retrieve scheduled tasks using Schedule.Service COMObject
PowerShell Magazine
External Articles
Get-ScheduledTask
My entries in TechNet Script Gallery

Update to my TechNet scripts

I upload some of my scripts into the TechNet Script Gallery and there are some lively discussions going on in the questions and answers sections of the scripts. I received feedback and based on that I have improved and updated some of my scripts.

The first script I would like to highlight is the Get-RemoteProgram script that has been built as a replacement for the Win32_Product WMI class. The Win32_Product class is useful but there are some downsides to this, have a look at this article for more information. This prompted me to write an alternative function for this purpose. This function generates a list by querying the registry and returning the installed programs of a local or remote computer. In the latest version of this script. There was an issue with some scenarios when running this script on a 32 bit machine which have been resolved in the latest version.

.EXAMPLE 
Get-RemoteProgram -ComputerName Server01 -Property DisplayVersion,VersionMajor 
 
Description: 
Will gather the list of programs from Server01 and attempts to retrieve the displayversion and versionmajor subkeys from the registry for each installed program 
 
.EXAMPLE 
'server01','server02' | Get-RemoteProgram -Property Uninstallstring 
 
Description 
Will retrieve the installed programs on server01/02 that are passed on to the function through the pipeline and also retrieves the uninstall string for each program

The second script that received an update is the Get-ScheduledTask the status of the tasks was listed in integers instead of ‘Running’,’Disabled’ or ‘Ready’. This has been updated and there were also scenarios in which the script would list the same task twice which has also been patched.

.EXAMPLE 
.\Get-ScheduledTask.ps1 -Computername mycomputer1

Description 
----------- 
This command query mycomputer1 and display a formatted list of all scheduled tasks on  that computer

Another script that I have updated is the Get-OrphanHomeFolder, this script takes a folder path as input and checks if the the folder has a corresponding samaccountname in Active Directory and if that is the case if the account is enabled or disabled. A request came in to also display the enabled users in order to get a full overview. Because of this I added the DisplayAll parameter to the script.

.PARAMETER DisplayAll 
This switch parameters will force the script to also display enabled active directory  accounts, can be used in combination with -FolderSize parameter. 

.EXAMPLE    
.\Get-OrphanHomeFolder.ps1 -HomeFolderPath \\Server01\Home -FolderSize -DisplayAll 
 
Description: 
Will list all the folders in the \\Server01\Home path. For each of these folders it    will query AD using the foldername, regardless of the AD results folder size will be returned 

The last script I updated is the Compare-ADuserAddGroupGUI this script compares the group membership between two users. The goal of this script is to grant the destination user all the missing memberships when compared to the source user. Any missing memberships will be added by this script and and any additional memberships will be removed. The ComputerName parameter has been added to this script in order to specify which domain controller will be queried for the comparison.

.EXAMPLE 
.\Compare-ADuserAddGroupGUI.ps1 testuserabc123 testuserabc456

Description 
----------- 
This command will add&remove from groups testuserabc456 to match groups that testuserabc123 is a member of the user is prompted by user interface to confirm these changes.

.EXAMPLE 
 .\Compare-ADuserAddGroupGUI.ps1

Description 
----------- 
Will use GUI to prompt for confirmation 

For a complete list of all my script feel free to browse to my submissions in the TechNet Script Gallery.

TechNet Script Gallery
My entries in TechNet Script Gallery
Get-RemoteProgram Get-ScheduledTask
Get-OrphanHomeFolder Compare-ADuserAddGroupGUI