Scheduled Tasks

Sometimes you want to run a powershell script with different credentials in form of a scheduled task.
I know that you could also encrypt the password etc but if you work on a locked down user it is not always working the way you like or suspect.Here is a simple scheduled task that I run with alternate credentials and have it start a powershell script which in his turn will run with encrypted passwords:

powershell -command &{powershell c:\temp\excel2.ps1}

this script will grab freediskspace and saves it into an excel file, if I don't run this as a admin user it will prompt me with every server again and again

If you want to see all the scheduled task on different servers throughout the domain, I made a script for that purpose:

# ==============================================================================================
# 
# Microsoft PowerShell Source File -- Created with SAPIEN Technologies PrimalScript 2009
# 
# NAME: Adavanced functions
# 
# AUTHOR: giant , 
# DATE  : 05-01-2011
# 
# COMMENT: This script will get the servernames and return in a csv all the scheduled tasks on these servers
# 
# ==============================================================================================

function get-stuff {
            [cmdletbinding()]
                param (
                    [parameter(position=0,Mandatory=$true,ValueFromPipeline=$true,ValueFromPipeLineByPropertyName=$true)]
                    [alias('host')]
                    $computername
                    )
                    BEGIN {}
                    PROCESS {
                    if ($psboundparameters.containskey('computername')) {
                        # we got parameter input
                        foreach ($name in $computername) {
                        stuffworker $name
                        }
                        } else {
                            # we got pipeline input
                            stuffworker $_
                        }
                    }
            END {}
}
function stuffworker {
param (
    $computername
    )

 schtasks /Query /FO CSV /s $computername /v >> C:\Temp\schtemp.csv
 $server
 $server >> "C:\Temp\schedlist.txt"
    }

#New-Alias gsf get-stuff
#Export-ModuleMember -Function get-stuff
#Export-ModuleMember -Alias gsf
# usage:
# Get-stuff server-r2
# get-stuff -computername server-r2
# get-stuff -computername (get-content names.txt)
# Get-Content names.txt | get-stuff
# Get-ADComputer -Filter * | select @{label='computername';Expression={$_.Name}} | Get-stuff

on me

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License