Scheduling a task with powershell

Good morning,
I have a powershell command that I want to schedule to run on Mondays and send an email to my email group, can someone assist me or provide a good resource to help out.
The command is to search for uses who have been inactive for 30 days.
Search-ADAccount -UsersOnly -AccountInactive -TimeSpan 30.00:00:00 | Where {$_.Enabled} | Sort Name | Get-ADUser -Prop DisplayName | Select Name,DisplayName | Out-File users.txt
Chad

I ran it in the run box, and this is what the output shows.
The term 'Search-ADAccount' is not recognized as the name of a cmdlet, function
, script file, or operable program. Check the spelling of the name, or if a pat
h was included, verify that the path is correct and try again.
At C:\temp\lastlogin.ps1:1 char:23
+ $body=Search-ADAccount <<<<  -UsersOnly -AccountInactive -TimeSpan 30.00:00:0
0 |
    + CategoryInfo          : ObjectNotFound: (Search-ADAccount:String) [], Co
   mmandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Send-MailMessage : Cannot validate argument on parameter 'Body'. The argument i
s null or empty. Supply an argument that is not null or empty and then try the
command again.
At C:\temp\lastlogin.ps1:5 char:184
+ send-mailmessage -to "Systems Engineering <[email protected]>" -from
"Inactive Accounts [email protected]" -subject "Accounts Inactive
for at least 30 days" -body <<<<  $body -smtpServer relay.itserve.com
    + CategoryInfo          : InvalidData: (:) [Send-MailMessage], ParameterBi
   ndingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
   Shell.Commands.SendMailMessage
Chad

Similar Messages

  • SP 2013 Workflow Associations - get the content type for associated tasks with PowerShell

    I am creating a PowerShell script to document SharePoint 2013 workflow associations on a site. I can get the Subscription object for the workflow association, but I can't figure out how to dig into it to find out the Content Type for tasks generated
    by workflows created by this WF association. I can get the Task List ID from the Subscription.PropertyDefinitions, and from there can get the Task List. But the task list may use many different content types, because when you associate a 2013 workflow
    to a list, SharePoint adds the workflow's content type to the set of content types used by the workflow task list. If you have a lot of workflows that use the same task list, that task list gets a lot of content types.
    I have the Subscription object for the workflow association. How can I divine the content type for tasks that the workflow will generate?
    Leigh Webber

    I would suggest you to consider using the SPListItem that running the workflow instance to check the task content type.
    First, find the list item that associated with the workflow, then SPListItem.Tasks returns a collection of workflow tasks for the item, you can check the content type from the task item.
    Qiao Wei
    TechNet Community Support

  • Creating a Scheduled Task using PowerShell v4

    So here is my question.  I'm trying/wanting to create a scheduled task using PowerShell v4 on Server 2012R2.  I want to task to run on the 1st day of every month.  The parameter for -Monthly -Day is not available.  I need to use PowerShell
    to create the Scheduled Task because the Task will be running with a group Managed Service Account credentials so the Scheduled Task can not be created via the Task Scheduler GUI.
    Thanks in Advance

    Here is a functioning task It can be easily edited in PowerShell or in notepad to alter the timing
    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.1" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
    <RegistrationInfo>
    <Author>W8TEST\user01</Author>
    </RegistrationInfo>
    <Triggers>
    <CalendarTrigger>
    <StartBoundary>2014-06-04T21:31:32.0459499</StartBoundary>
    <Enabled>true</Enabled>
    <ScheduleByMonth>
    <DaysOfMonth>
    <Day>1</Day>
    <Day>12</Day>
    <Day>24</Day>
    </DaysOfMonth>
    <Months>
    <January />
    <February />
    <March />
    <April />
    <May />
    <June />
    <July />
    <August /
    <September />
    <October />
    <November />
    <December />
    </Months>
    </ScheduleByMonth>
    </CalendarTrigger>
    </Triggers>
    <Principals>
    <Principal id="Author">
    <RunLevel>LeastPrivilege</RunLevel>
    <UserId>W8TEST\jvierra</UserId>
    <LogonType>InteractiveToken</LogonType>
    </Principal>
    </Principals>
    <Settings>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <IdleSettings>
    <StopOnIdleEnd>true</StopOnIdleEnd>
    <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
    </Settings>
    <Actions Context="Author">
    <Exec>
    <Command>notepad.exe</Command>
    <Arguments>test.txt</Arguments>
    <WorkingDirectory>c:\temp</WorkingDirectory>
    </Exec>
    </Actions>
    </Task>
    I have edited and reloaded the XML many, many times.  It works very nicely.
    ¯\_(ツ)_/¯

  • Task Scheduled Start Date with RAPI

    Task Scheduled Start Date with RAPI
    Is it possible to have a scheduled start date for a task in a service that is generated by RAPI, and, which does not have any authorizations/reviews? RAPI seems to throw the request into the service delivery moment without calculating the tasks even if I supply a date onload (in a field for the task start date to use). It works fine if there are authorizations or reviews, which is expected, but I can't get it to work without them. Thanks!

    Fascinating. As a workaround could you try throwing in a dummy authorization? For example, externalize it with ServiceLink dummy and autocomplete adapters, or keep it internal, but conditional with a condition that would always be false.

  • Task Scheduler Won't Run Task With Idle Condition

    When I schedule a task to run Disk Cleanup with a one minute idle condition the task does does not run successfully and provides the following run result.
    The Task Scheduler service has asked the task to run. (0x41325)
    If I manually run the task or remove the idle condition the task runs and completes successfully.
    Why won't the task start with an idle condition?

    Hi,
    I noticed that you set the idle time shorter than the waiting for idle time. In my opinion, we should set the idle time longer than the waiting for idle time if we schedule a task running during the idle contidion. As the documents described, the Task Scheduler service will verify that the computer is in an idle state every 15 minutes. If a task is set to start only if the computer is idle for 30 minutes, and the task waits for the computer to be idle for 10 minutes, then the task will launch in 5 minutes only if the computer has been idle for 25 minutes prior to the time the trigger was activated. The task will not start if the computer enters an idle state 5 minutes after the trigger is activated. For more information, please refer to Task Idle Conditions.
    Best Regards
    Dale

  • Scheduled Recurring Incidents with checklists

    Hi All,
    I would like to find out if it is possible to setup scheduled recurring incidents with specific info entered under description and checklists attached to forms for routine tasks please?
    An example would be to create an incident and assign it to a specific support person for a weekly monitoring task E.g:
    Title: Weekly Monitoring <Date insert>
    Description: Perform monitoring on ABC server / Checkup Backup logs
    Checklist: Task A [], Task B [] or even a word doco attached
    Category = Backup Monitoring - Weekly
    I can see that it is possible to create recurring incidents using the workflows on the authoring tool however there are only limited fields you can fill in from what I can see.
    Thanks in advance,
    Ves

    I don't know if it can be done with the authoring tool or the console's "workflow" setup, but it can be done (I've done it). There are a couple ways..I'll first describe the way I've implemented it.
    Set up a workflow that creates your incident from a template. This workflow could be powershell based or C# based..any method through which you can use the SDK to create an incident with a template.
    This workflow will trigger when an incident, previously created by the workflow, has been closed or resolved.
    How will the workflow know which incident has been previously created by itself? Give it a unique marker..for example, in the notes field of your incident's template you could put something like "recurring incident". Your workflow's trigger criteria,
    then, would trigger on an incident that closes and whose notes field contains "recurring incident".
    Basically, you'll create a self-recreating incident. When the engineer closes or resolves the incident, another one will generate right away. You can put a 7-day SLA on the incident so the engineers know that they should work on the incident within that
    7 day period.
    The other method is to, again, setup a workflow that runs on a timer. It simply executes every 7 days and does the same thing whether the previous incident is closed or not. The risk in that method is, of course, if your workflow engine goes down it may
    not generate another incident until another 7 days has passed.
    Finally, why are you generating recurring incidents? In the ITIL world, incidents are used to track unexpected issues, not routine tasks. I recommend you use a service request record instead, if you can.

  • Creating Windows Basic Task using powershell

    Hello Everyone,
    Please help me out in the below situation:
    I have to create a basic windows task using powershell to run a script on a specific date and time.
    Let me make it even clear :
    I have a csv say,
    D:\xyz.csv
    ServerName ,  Date  , Time
    Random1,   11/15/2014,01:00:00PM
    Random2,   12/01/2015,03:00:00PM
    ...and so on
    I also have a script at E:\TestingServer.ps1
    I need to create list of windows tasks to invoke TestingServer.ps1 with parameters as servername and Time of task as given date and time in csv.
    Task1- with input as ServerName at Date and time from CSV
    Task2-with input as ServerName at Date and time from CSV

    Well here is a good article showing howto do this:
    http://blogs.technet.com/b/heyscriptingguy/archive/2012/09/18/create-a-powershell-scheduled-job.aspx
    ¯\_(ツ)_/¯

  • Trying to delete a file with Powershell script ran by a service but issues with uac

    I'm having issues with a script that will delete a file on the C-Drive of a server. the script looks like this:
    param(
    [Parameter(Mandatory=$true)][string]$hostname
    $StrFileName = "C:\Program Files\NSClient++\nsclient.log"
    $LogLocal="c:\Nagios\naf_delete_nscp_log_file.log"
    $Date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"
    "$date : NSClient logfile deletion requested on $hostname" | Out-File -filepath $LogLocal -Append
    If (Test-Path "$strFileName"){
    Remove-Item $strFileName -Force
    $Date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"
    "$date : NSClient logfile deleted on $hostname" | Out-File -filepath $LogLocal -Append
    The script is initiated from a Nagios quick action which will use nrpe to pass the host as parameter and make the nscp service, which runs as local system, run it. It works perfectly on servers that have no uac enabled, but I can't get it to work on servers
    with uac. I've tried numerous options, but none seem to work. Any tips or advice to get this working with Powershell v2 code on servers with uac enabled is highly appreciated.
    Thanks.
    Willem

    Hi Willem,
    one thing to note: I don't see why your script itself has a hostname parameter.
    One way around UAC has always been the Windows Task Scheduler. If you register a task as System run and triggered by an event, you can simply call the event locally (which doesn't require admin permissions) and it will perform the task.
    I don't know how your Nagios construct works and the script by itself doesn't make much sense. If you want advice on how to do this without resorting to tasks, I'd need to know more about the system you are using.
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • Read Outlook Email and Get Specific Content from Mail with PowerShell

    Hi Everyone,
    I would like to get full content value by searching in mail body with PowerShell but I stuck at one place in scripting and would required help from your side. Below is my script with description.
    #Connecting Outlook with below command
    $Outlook = New-Object -ComObject Outlook.Application
    # Now getting all folders info in variable (Shows Email, Calendar, Tasks etc)
    $OutlookFolders = $Outlook.Session.Folders.Item(1).Folders
    #Now connecting Inbox mails
    $OutlookInbox = $Outlook.session.GetDefaultFolder(6)
    #Now reading latest mail
    $latestmail=$OutlookInbox.items | select -last 1
    #Now calling email content and getting email content as output in html
    $latestmail.HTMLBody
    #below is output
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
    <HTML>
    <HEAD>
    <META NAME="Generator" CONTENT="MS Exchange Server version 14.00.0004.000">
    <TITLE></TITLE>
    </HEAD>
    <BODY>
    <!-- Converted from text/plain format -->
    <P><FONT SIZE=2><A HREF="https://test.abc.com/sys/servlet/ViewFormServlet?f
    orm=NTE%3aNotifier&server=sm.user&eid=NTS000299462947">https://test.abc.com/sys/servlet/ViewFormServlet?form=NTE%3aNotifier&server=sm.user&eid=NTS4556555
    294437</A><BR>
    <BR>
    Incident IND000008655308 has been assigned to your group 'Windows
    ADMINISTRATION'.<BR>
    Company: ABC<BR>
    Customer Name: XYZ<BR>
    Service Type: Infrastructure Event<BR>
    Priority: High<BR>
    SLA Resolve Target Status: Within the Service Target<BR>
    SLA Response Target Status:<BR>
    Reported Source: Systems Management<BR>
    *******************************************************************<BR>
    Summary: server1.abc.com: Average (5 samples) total cpu is now 100.0
    0%, which is above the error t<BR>
    <BR>
    *******************************************************************<BR>
    Notes: server1.abc.com: Average (5 samples) total cpu is now 100.00%
    , which is above the error threshold (100%)</FONT></P>
    </BODY>
    </HTML>
    # Now my target is to search incident number which is starting from IND* and server name (server1.abc.com). I tried below code but not getting value. Please help me to get these two values from email.
    $latestmail.HTMLBody -match "IND"
    #Output
    True
    #but not getting full that is IND000008655308.
    Please help me.

    Try this:
    if($latestmail.HTMLBody -match 'IND(?<x>\d+)\S'){
    $value='IND'+$matches['x']
    }else{
    Write-Host 'Not found'
    \_(ツ)_/

  • Scheduling a task 1 year (365 days) out

    I am trying to schedule a task for 365 days out (1 year/52 weeks) and am encountering errors with the automatic scheduling. Work will be performed on the weekends, year-round, from 8:00 AM to 5:00 PM. I have set the "Change Working Time" options
    to consider the weekends working days, as well as set up my Scheduling default Options to: "Sunday week start"; "8 hour days"; "56 hours per week"; and "30 days per month".  However, when I enter 365 days under
    duration, the automatic scheduling is completely off.  Very frustrating... Please help!!

    Hi,
    I just ran a test and the task was scheduled accordingly
    What I have done was to set the Saturday and Sunday as working days in Change Working time
    if you are using 'days' to schedule your tasks, there is no need to change the other options (e.g. Hours per week)
    If you are assigning resources to your task, make sure the resource calendar is also having Saturday and Sunday as working days
    Hope this helps
    Paul

  • Sync outlook tasks with iphone 4

    Iphone 4 with icloud and iOS 6.1.2; MS Outlook 2007 on 32 bit win 7 OS.
    How can I sync Outlook's "tasks" with my iphone via iCloud?  Barring iCloud, what other options do I have for syncing tasks? 
    Basically, I am trying to keep everything functioning as simply as possible, as inexpensively as possible (I'm a student juggling schedules).  I would like to continue using Outlook, but I am open to suggestions for other software/apps that have similar capabilities and functionality.  I already have my calendars synced over the cloud, but I can't figure out how to sync tasks.  I prefer using tasks for simple 'to-do' type stuff, and my calendars for appointments, time sensitive things, etc.

    For email, available with an Exchange or IMAP account only, not with a POP account.
    All server stored mailboxes with an Exchange or IMAP account are kept synchronized with the server with each email client used to access the account.
    Although it is possible to access a POP account with more than one email client, a POP account is designed to be accessed with a single email client only.

  • Scheduled Planner tasks and control validity

    Use case is outlined below:
    Local Control A is valid from 1/1/14 to 12/31/14. I'm trying to schedule a planner task with activity 'Test Control Effectiveness' for this local control. The task being scheduled is a recurring task starting from 1/1/15 to 1/1/17. As can be seen the planner task start date is post the 'Valid To' date of the control. So, essentially the control is not active during the duration for which the planner task is scheduled for. The system did not show an error message. Is this expected behavior? Also, even after I delete the scheduled planner task, I can no longer revise the 'Valid To' of the local control.
    I'd appreciate any document that outlines the pre-requisites for selecting object(s) within different planner tasks.
    Appreciate any help I can get with this!
    Thanks,
    Anju.

    I don't know what Control-M is, but if it can invoke a java task, then it can connect to OIM and start the scheduled task.
    A scheduled task doesn't have to be run within OIM. The scheduler within OIM simply provides a way to invoke the java code that performs tasks or Recons within OIM. So long as your system can run java to connect to OIM and run some code, you can run it in whatever way you'd like.
    -Kevin

  • How to manage tasks with variable duration / amount of work

    Hello,
    I'm currently trying to build a macro planning for my department for the next 2 years.
    In my plan, there is a task that has a variable duration and amount of work. People will start / stop working on it depending on the beginning / end of other tasks. The only way to do this I've found so far is to split the task into multiple subtasks
    (one per resource) that are manually scheduled with start and end dates linked to the dates of the tasks they depend on. However, I think this workaround is really not practical and hard to manage since for each subtask I need to create milestones for linking
    the start date to the next working day. Relationships between tasks are also not visible in the plan. I've also read that in general it' better to avoid using links, but is there a better way to manage this in Project 2013 ?
    Best regards,
    Sébastien.

    Seb_Lz,
    There are several elements of your description that need more detail.
    You mention a variable duration. That could simply be a normal task that changes scope as the plan progresses (i.e. more work content, slipping schedule, etc.), or it could be indicative of what is called a hammock task (See Faq 19 on the MVP website at: http://project.mvps.org/faqs.htm).
    You mention linking as a way to define task dependencies. That is exactly what task predecessors and successors are designed to do. Task links have nothing to do with resources. It's not clear why you say only one resource per task.
    You talk about manual scheduling and entering start and finish dates. Manual scheduling is intended for a very rough first cut at a working schedule. To get the full benefit of Project's scheduling engine, tasks should be auto-scheduled and the whole logic
    network sequence of tasks should be defined by durations and links, not by manually entering dates. It's fine to set critical milestones or use Project's deadline feature, but otherwise let Project tell you how your plan all works given the basic data.
    You say relationships are not visible in the plan. Don't understand that at all since link lines between tasks are shown by default in task views (e.g. Gantt Chart view).
    Not sure where you read that it is better to avoid using links because that is flat out wrong, at least for normal predecessor/successor links within a single file. If you are working with a linked structure (i.e. master/subproject), or using external predecessors/successors,
    then yes, links become a whole new area of concern.
    John

  • Managing from Powershell 4 machines with Powershell 2 (WinRM)

    Hi,
    is it possible to manage machines which have powershell 2 installed from a machine with powershell 4?
    Background: I plan to write a script running in powershell 4 and like to query servers with have either powershell 2 or powershell 4 installed.
    Is that possible? Is there something I need to consider?
    Thanks for your feedback
    Ruben

    You cannot get scheduling from WMI.
    You do not need WinRM to use WMI.  WF does not necessrilu use WInRM.  These are all separate technologies in WIndows that just happen to be available to PowerShell.
    Start by learning how Windows works and what all of these technologies do.
    You cannot guess your way through any of this.  Without good fundamtentals in WIndows technologies you will not be able to understand the lessons or discussions.
    Here is a blog that has many good backgrounders and examples:
    https://social.technet.microsoft.com/Search/en-US?query=workflow&rn=Hey,%20Scripting%20Guy!%20Blog&rq=site:blogs.technet.com/b/heyscriptingguy/&beta=0&ac=2
    ¯\_(ツ)_/¯

  • Facility of Scheduling background tasks  in jdk1.2.2 as avb in jdk1.3

    JDK1.3 - java.util.Timer
    A facility for threads to schedule tasks for future execution in a background thread. Tasks may be scheduled for one-time execution, or for repeated execution at regular intervals.
    I want to know what is alternate to this in jdk1.2.2.
    I want to schedule teh tasks for thread to run in background in future using jdk1.2.2.

    Hello all,
    Is there a timer class that I can use for a stopwatch program for PersonalJava, which uses jdk 1.2.2? The java.util.Timer class is available starting with jdk 1.3. I've seen reference to a class called PTimer, but I can't find it. Nor can I find the pj.jar file which is supposed to contain PTimer.
    thanks,
    Harry Mitchell

Maybe you are looking for

  • OpenCL Mac mini / GeForce 9400M support?

    Anyone that can confirm that the OpenCL version included in Snow Leopard 10.6 supports the "newer" Mac mini's NVIDIA GeForce 9400M graphics processor?

  • Can't find BI Beans Help topic

    I've installed JDeveloper 10.1.2.1.0 (build 1913) and Bi Beans 10.1.2.1, but I do not see the "Building Applications with BI Beans" Help topic within JDeveloper. How do I get access to this Help file? Can it be accessed somewhere other than within JD

  • What year was MacPro3,1 created

    Can I update this Mac Pro to Mt Lion?

  • I can't enter any values in JTextField after loading the flash files.

    Hi to all, In my application I have two panels. One panel has JTextField and another panel i loaded flash files. The flash files are build by CS4. I'm using JDIC to load the flash files. While open the application i loaded flash file and I try to ent

  • Lightroom 1.4

    This is just to add additional information about a problem that seems well represented here.. Upgrated to LR 1.4, and get "AN UNKNOWN ERROR OCCURRED" after importing and converting to DNG. HOWEVER . . . that only happens for photos in landscape orien