{"id":248,"date":"2012-05-10T15:42:09","date_gmt":"2012-05-10T22:42:09","guid":{"rendered":"https:\/\/mmman.itgroove.net\/2012\/05\/powershell-script-to-log-to-event-viewer-and-reboot\/"},"modified":"2023-02-24T21:47:03","modified_gmt":"2023-02-24T21:47:03","slug":"powershell-script-to-log-to-event-viewer-and-reboot","status":"publish","type":"post","link":"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/","title":{"rendered":"PowerShell Script to Log to Event Viewer and Reboot"},"content":{"rendered":"<p>We recently needed to create a PowerShell script to log to the event viewer and reboot the machine on a schedule.&#160; This is what we came up with.<\/p>\n<h2>The PowerShell<\/h2>\n<p><font size=\"2\" face=\"Courier New\">$evt=new-object System.Diagnostics.EventLog(&quot;Application&quot;)      <br \/>$evt.Source=&quot;itgroove Scheduled Reboot&quot;       <br \/>$infoevent=[System.Diagnostics.EventLogEntryType]::Information       <br \/>$vdate=Get-Date       <br \/>$val=&quot;itgroove Scheduled Reboot Event at: [&quot;+$vdate+&quot;]&quot;       <br \/>$evt.WriteEntry($val,$infoevent,70)       <br \/>Restart-Computer \u2013Force<\/font><\/p>\n<p>You simply put this into a file (such as C:TOPSharePointreboot.ps1)<\/p>\n<p>Basically, the script breaks down as this:<\/p>\n<p>Line 1 \u2013 Choose the \u201cApplication\u201d event log (you can see this in the screen capture below at the very top)    <br \/>Line 2 \u2013 The event source (the name of the script logging the event \u2013 this can be whatever you want it to be)     <br \/>Line 3 \u2013 This is just an Information event (as opposed to a Warning, Error, Critical)     <br \/>Line 4 \u2013 Get the current date stamp     <br \/>Line 5 \u2013 Assemble the line we\u2019re going to log as the \u201cdetails\u201d of the event     <br \/>Line 6 \u2013 Actually write the event to the log (the last parameter is the application specific Event ID \u2013 in our case we choose the number 70 \u2013 this is a number you choose as the writer of this script)     <br \/>Line 7 \u2013 Reboot the machine<\/p>\n<p>This is how it maps to the event viewer:<\/p>\n<p><font size=\"2\" face=\"Courier New\">1 = $evt.Source=&quot;<font color=\"#0000ff\"><strong>itgroove Scheduled Reboot<\/strong><\/font>&quot; (line 2 in the code above)<\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">2 = $val=&quot;<font color=\"#0000ff\"><strong>itgroove Scheduled Reboot Event at: [&quot;+$vdate+&quot;]<\/strong><\/font>&quot; (line 5 above)<\/font><\/p>\n<p><font size=\"2\" face=\"Courier New\">3 = $evt.WriteEntry($val,$infoevent,<font color=\"#0000ff\"><strong>70<\/strong><\/font>) (line 6 above)<\/font><\/p>\n<p><a href=\"https:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image16.png\"><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb16.png\" width=\"658\" height=\"307\" \/><\/a><\/p>\n<h2>The Shell Script<\/h2>\n<p>@ECHO OFF    <br \/>ECHO Performing Reboot     <br \/>POWERSHELL &quot;&amp; &#8216;C:TOPSharePointreboot.ps1&#8217;&quot;<\/p>\n<p>You simply put this into a file (such as C:TOPSharePointreboot.cmd)<\/p>\n<h2>The Schedule<\/h2>\n<p>The last step you have to do is add the above shell script (reboot.cmd) to the task scheduler, and you\u2019re off to the races.    <\/p>\n","protected":false},"excerpt":{"rendered":"<p>We recently needed to create a PowerShell script to log to the event viewer and reboot the machine on a schedule.&#160; This is what we came up with. The PowerShell $evt=new-object System.Diagnostics.EventLog(&quot;Application&quot;) $evt.Source=&quot;itgroove Scheduled Reboot&quot; $infoevent=[System.Diagnostics.EventLogEntryType]::Information $vdate=Get-Date $val=&quot;itgroove Scheduled Reboot Event at: [&quot;+$vdate+&quot;]&quot; $evt.WriteEntry($val,$infoevent,70) Restart-Computer \u2013Force You simply put this into a file (such as &hellip; <a href=\"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/\"><\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[31,33],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PowerShell Script to Log to Event Viewer and Reboot - Archive<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PowerShell Script to Log to Event Viewer and Reboot - Archive\" \/>\n<meta property=\"og:description\" content=\"We recently needed to create a PowerShell script to log to the event viewer and reboot the machine on a schedule.&#160; This is what we came up with. The PowerShell $evt=new-object System.Diagnostics.EventLog(&quot;Application&quot;) $evt.Source=&quot;itgroove Scheduled Reboot&quot; $infoevent=[System.Diagnostics.EventLogEntryType]::Information $vdate=Get-Date $val=&quot;itgroove Scheduled Reboot Event at: [&quot;+$vdate+&quot;]&quot; $evt.WriteEntry($val,$infoevent,70) Restart-Computer \u2013Force You simply put this into a file (such as &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/\" \/>\n<meta property=\"og:site_name\" content=\"Archive\" \/>\n<meta property=\"article:published_time\" content=\"2012-05-10T22:42:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-24T21:47:03+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb16.png\" \/>\n<meta name=\"author\" content=\"Colin Phillips (Alumni)\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Colin Phillips (Alumni)\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/\",\"url\":\"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/\",\"name\":\"PowerShell Script to Log to Event Viewer and Reboot - Archive\",\"isPartOf\":{\"@id\":\"https:\/\/regroove.ca\/archive\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb16.png\",\"datePublished\":\"2012-05-10T22:42:09+00:00\",\"dateModified\":\"2023-02-24T21:47:03+00:00\",\"author\":{\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b\"},\"breadcrumb\":{\"@id\":\"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/#primaryimage\",\"url\":\"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb16.png\",\"contentUrl\":\"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb16.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog Archive\",\"item\":\"https:\/\/regroove.ca\/archive\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PowerShell Script to Log to Event Viewer and Reboot\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/regroove.ca\/archive\/#website\",\"url\":\"https:\/\/regroove.ca\/archive\/\",\"name\":\"Archive\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/regroove.ca\/archive\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b\",\"name\":\"Colin Phillips (Alumni)\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g\",\"caption\":\"Colin Phillips (Alumni)\"},\"url\":\"https:\/\/regroove.ca\/archive\/author\/cphillips\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PowerShell Script to Log to Event Viewer and Reboot - Archive","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/","og_locale":"en_US","og_type":"article","og_title":"PowerShell Script to Log to Event Viewer and Reboot - Archive","og_description":"We recently needed to create a PowerShell script to log to the event viewer and reboot the machine on a schedule.&#160; This is what we came up with. The PowerShell $evt=new-object System.Diagnostics.EventLog(&quot;Application&quot;) $evt.Source=&quot;itgroove Scheduled Reboot&quot; $infoevent=[System.Diagnostics.EventLogEntryType]::Information $vdate=Get-Date $val=&quot;itgroove Scheduled Reboot Event at: [&quot;+$vdate+&quot;]&quot; $evt.WriteEntry($val,$infoevent,70) Restart-Computer \u2013Force You simply put this into a file (such as &hellip;","og_url":"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/","og_site_name":"Archive","article_published_time":"2012-05-10T22:42:09+00:00","article_modified_time":"2023-02-24T21:47:03+00:00","og_image":[{"url":"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb16.png"}],"author":"Colin Phillips (Alumni)","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Colin Phillips (Alumni)","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/","url":"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/","name":"PowerShell Script to Log to Event Viewer and Reboot - Archive","isPartOf":{"@id":"https:\/\/regroove.ca\/archive\/#website"},"primaryImageOfPage":{"@id":"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/#primaryimage"},"image":{"@id":"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/#primaryimage"},"thumbnailUrl":"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb16.png","datePublished":"2012-05-10T22:42:09+00:00","dateModified":"2023-02-24T21:47:03+00:00","author":{"@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b"},"breadcrumb":{"@id":"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/#primaryimage","url":"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb16.png","contentUrl":"http:\/\/mmman.itgroove.net\/wp-content\/uploads\/mmman\/2012\/05\/image_thumb16.png"},{"@type":"BreadcrumbList","@id":"https:\/\/regroove.ca\/archive\/2012\/05\/10\/powershell-script-to-log-to-event-viewer-and-reboot\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Archive","item":"https:\/\/regroove.ca\/archive\/"},{"@type":"ListItem","position":2,"name":"PowerShell Script to Log to Event Viewer and Reboot"}]},{"@type":"WebSite","@id":"https:\/\/regroove.ca\/archive\/#website","url":"https:\/\/regroove.ca\/archive\/","name":"Archive","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/regroove.ca\/archive\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b","name":"Colin Phillips (Alumni)","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g","caption":"Colin Phillips (Alumni)"},"url":"https:\/\/regroove.ca\/archive\/author\/cphillips\/"}]}},"_links":{"self":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/248"}],"collection":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/comments?post=248"}],"version-history":[{"count":1,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/248\/revisions"}],"predecessor-version":[{"id":1995,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/248\/revisions\/1995"}],"wp:attachment":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/media?parent=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/categories?post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/tags?post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}