ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Powershell output in Email is Possible

    IT Discussion
    powershell send-mailmessage windows scripting
    5
    21
    3.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ObsolesceO
      Obsolesce
      last edited by

      Here is a script I made to set up a scheduled task to either launch a PowerShell script, or a batch file.

      Comment out the $action line that you do NOT want to use. The below script will create a scheduled task that launches a PowerShell script called psScript.ps1.

      Note that you must execute these lines in an elevated PowerShell window.

      #Requires -RunAsAdministrator
      
      $action = New-ScheduledTaskAction -Execute 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -Argument "-ExecutionPolicy bypass -NonInteractive -NoLogo -NoProfile -File '\\server\path\to\psScript.ps1'"
      # $action = New-ScheduledTaskAction -Execute '\\server\path\to\batchFile.bat'
      $trigger = New-ScheduledTaskTrigger -AtLogon
      $principal = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" -RunLevel Highest
      $settings = New-ScheduledTaskSettingsSet
      $task = New-ScheduledTask -Action $action -Trigger $trigger -Principal $principal -Settings $settings
      Register-ScheduledTask -TaskName "kickoff" -InputObject $task
      

      If you choose to launch the PowerShell script via a batch file, here's what you need to have in your .bat file:

      Powershell.exe -executionpolicy bypass -File "\\server\path\to\psScript.ps1"
      
      1 Reply Last reply Reply Quote 0
      • 1
      • 2
      • 2 / 2
      • First post
        Last post