{"id":52553,"date":"2009-09-02T03:01:00","date_gmt":"2009-09-02T03:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/09\/02\/hey-scripting-guy-can-windows-powershell-alleviate-my-need-to-type-dates\/"},"modified":"2009-09-02T03:01:00","modified_gmt":"2009-09-02T03:01:00","slug":"hey-scripting-guy-can-windows-powershell-alleviate-my-need-to-type-dates","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-can-windows-powershell-alleviate-my-need-to-type-dates\/","title":{"rendered":"Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?"},"content":{"rendered":"<p><SPAN class=\"sbmLink\">\n<TABLE cellSpacing=\"1\" cellPadding=\"1\">\n<TBODY>\n<TR>\n<TD class=\"sbmText\">Share this post: <\/TD>\n<TD><A title=\"Post it to backflip\" href=\"http:\/\/www.backflip.com\/add_page_pop.ihtml?url=http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/02\/hey-scripting-guy-september-2-2009.aspx&amp;title=Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?\" target=\"_blank\"><IMG border=\"0\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/backflip4.png\"><\/A><\/TD>\n<TD><A title=\"Post it to buddymark\" href=\"http:\/\/buddymarks.com\/s_add_bookmark.php?bookmark_url=http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/02\/hey-scripting-guy-september-2-2009.aspx&amp;bookmark_title=Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?\" target=\"_blank\"><IMG border=\"0\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/buddymar4.png\"><\/A><\/TD>\n<TD><A title=\"Post it to del.icio.us\" href=\"http:\/\/del.icio.us\/post?url=http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/02\/hey-scripting-guy-september-2-2009.aspx&amp;;title=Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?\" target=\"_blank\"><IMG border=\"0\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/deliciou4.png\"><\/A><\/TD>\n<TD><A title=\"Post it to digg\" href=\"http:\/\/digg.com\/submit?phase=2&amp;url=http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/02\/hey-scripting-guy-september-2-2009.aspx&amp;title=Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?\" target=\"_blank\"><IMG border=\"0\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/digg14.png\"><\/A><\/TD>\n<TD><A title=\"Post it to Facebook\" href=\"http:\/\/www.facebook.com\/sharer.php?u=http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/02\/hey-scripting-guy-september-2-2009.aspx&amp;t=Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?\" target=\"_blank\"><IMG border=\"0\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/telligent.evolution.components.attachments\/13\/4982\/00\/00\/01\/76\/53\/19\/facebook.JPG\"><\/A><\/TD>\n<TD><A title=\"Post it to furl\" href=\"http:\/\/www.furl.net\/store?s=f&amp;to=0&amp;u=http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/02\/hey-scripting-guy-september-2-2009.aspx&amp;ti=Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?\" target=\"_blank\"><IMG border=\"0\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/furl4.png\"><\/A><\/TD>\n<TD><A title=\"Post it to netvouz!\" href=\"http:\/\/netvouz.com\/action\/submitBookmark?url=http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/02\/hey-scripting-guy-september-2-2009.aspx&amp;title=Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?\" target=\"_blank\"><IMG border=\"0\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/netvouz4.png\"><\/A><\/TD>\n<TD><A title=\"Post it to reddit!\" href=\"http:\/\/reddit.com\/submit?url=http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/02\/hey-scripting-guy-september-2-2009.aspx&amp;title=Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?\" target=\"_blank\"><IMG border=\"0\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/reddit4.png\"><\/A><\/TD>\n<TD><A title=\"Post it to spurl\" href=\"http:\/\/www.spurl.net\/spurl.php?v=3&amp;url=http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/02\/hey-scripting-guy-september-2-2009.aspx&amp;title=Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?\" target=\"_blank\"><IMG border=\"0\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/spurl8.png\"><\/A><\/TD>\n<TD><A title=\"Post it to Technorati!\" href=\"http:\/\/technorati.com\/faves\/?add=http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/02\/hey-scripting-guy-september-2-2009.aspx&amp;title=Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?\" target=\"_blank\"><IMG border=\"0\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/technora4.png\"><\/A><\/TD>\n<TD><A title=\"Post it to wists\" href=\"http:\/\/www.wists.com\/?action=add&amp;url=http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/02\/hey-scripting-guy-september-2-2009.aspx&amp;title=Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?\" target=\"_blank\"><IMG border=\"0\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/wists9.png\"><\/A><\/TD>\n<TD><A title=\"Post it to Yahoo!\" href=\"http:\/\/myweb.yahoo.com\/myresults\/bookmarklet?u=http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/02\/hey-scripting-guy-september-2-2009.aspx&amp;t=Hey, Scripting Guy! Can Windows PowerShell Alleviate My Need to Type Dates?\" target=\"_blank\"><IMG border=\"0\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/yahoo9.png\"><\/A><\/TD><\/TR><\/TBODY><\/TABLE><\/SPAN>\n<P class=\"MsoNormal\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"><\/P>\n<P class=\"MsoNormal\">Hey, Scripting Guy! I hate typing dates. There are several ways of typing dates, and they are all a pain. I do not like having to type the numbers and the whacks, and I do not like having to spell out month names, or attempting to remember if it is month first or day first. I like scripting, but I also like pointing and clicking. Is there something you can do for me? <\/P>\n<P class=\"MsoNormal\">&#8212; RS <BR><\/P>\n<P><SPAN><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><\/SPAN><\/P>\n<P>Hello RS, <\/P>\n<P>Microsoft Scripting Guy Ed Wilson here. I am glad you took the time to send an e-mail to <A href=\"mailto:scripter@microsoft.com\"><FONT face=\"Segoe\">scripter@microsoft.com<\/FONT><\/A> because today I am in virtual meetings for 9 hours! I love meetings because I work from home, and I do not get to interact with Microsoftees too often unless I head to the office (a couple hour trek), am on campus in Redmond, speak at a conference such as Tech<SPAN>\u2219<\/SPAN>Ed or TechReady, or attend a virtual meeting. Of course, a Scripting Guy cannot spend all of his time in meetings, but he can always try. <\/P>\n<P class=\"MsoNormal\">Interestingly enough, when I was teaching my VBScript class at the Microsoft office in <A href=\"http:\/\/en.wikipedia.org\/wiki\/Sao_Paulo,_Brazil\"><FONT face=\"Segoe\">Sao Paulo, Brazil<\/FONT><\/A>, one of my friends told me they were having problems getting people to attend meetings. He had however come up with the solution&#8230;Meeting Miles. You get 1 meeting mile for every hour you spend in a meeting (kind of like airline miles). At the end of the month, you can redeem your meeting miles for rewards and for prizes. You could even offer to attend meetings for other people to accrue meeting miles more rapidly. Great idea. I would be able to fly to Hawaii for free twice a year, if we implemented that in my organization. <\/P>\n<P class=\"MsoNormal\">I have gotten pretty good at multitasking (but that is the good thing about having a Scripting Wife who reads all of my Hey, Scripting Guy! articles and Craig who edits all my Hey, Scripting Guy! articles), but at times I do get confused and errors of both omission and commission are ultimately mine. <\/P>\n<P class=\"MsoNormal\">RS, I took the opportunity to write the Get-DatePickerFunction.ps1 script for you. The <STRONG>DatePicker<\/STRONG> will definitely solve your date issues by alleviating your need for typing dates. The full Get-DatePickerFunction.ps1 script is seen here. <\/P>\n<P class=\"CodeBlockScreenedHead\"><STRONG>Get-DatePickerFunction.ps1 <\/STRONG>\n<P class=\"CodeBlockScreened\"><SPAN><FONT><FONT face=\"Lucida Sans Typewriter\">Function Get-DatePicker <BR>{<SPAN>&nbsp;&nbsp; <\/SPAN><BR><SPAN>&nbsp;<\/SPAN>[System.Reflection.Assembly]::LoadWithPartialName(&#8220;System.windows.forms&#8221;) | <BR><SPAN>&nbsp;<\/SPAN>Out-Null <BR><SPAN>&nbsp;<\/SPAN> <BR><SPAN>&nbsp;<\/SPAN>$WinForm = New-Object Windows.Forms.Form<SPAN>&nbsp;&nbsp; <\/SPAN><BR><SPAN>&nbsp;<\/SPAN>$WinForm.text = &#8220;DatePicker Control&#8221;<SPAN>&nbsp;&nbsp; <\/SPAN><BR><SPAN>&nbsp;<\/SPAN>$WinForm.Size = New-Object Drawing.Size(205,55) <BR><BR><SPAN>&nbsp;<\/SPAN>$DatePicker = New-Object System.Windows.Forms.DateTimePicker<SPAN>&nbsp;&nbsp; <\/SPAN><BR><SPAN>&nbsp;<\/SPAN>#$DatePicker.Format = [windows.forms.datetimepickerFormat]::custom <BR><SPAN>&nbsp;<\/SPAN>#$DatePicker.CustomFormat = &#8220;MM-dd-yyyy&#8221; <BR><SPAN>&nbsp;<\/SPAN>$WinForm.Controls.Add($DatePicker)<SPAN>&nbsp;&nbsp; <\/SPAN><BR><SPAN>&nbsp;<\/SPAN> <BR><SPAN>&nbsp;<\/SPAN>$WinForm.Add_Shown($WinForm.Activate())<SPAN>&nbsp; <\/SPAN><BR><SPAN>&nbsp;<\/SPAN>$WinForm.showdialog() | Out-Null<SPAN>&nbsp; <\/SPAN><BR><SPAN>&nbsp;<\/SPAN>$DatePicker.value <BR>} #end function Get-DatePicker <BR><BR># *** Entry point to script *** <BR><BR># Get-EventLog -LogName application -After [datetime](Get-Datepicker) # Windows PowerShell 2.0 call <BR># wps 1.0 version of call <BR>$dte = [datetime](Get-DatePicker) <BR>Get-EventLog -LogName application | <BR>Where-Object { $_.timeWritten -gt $dte } <\/FONT>\n<P><\/FONT><\/SPAN>When the Get-DatePickerFunction.ps1 script runs, the very small dialog box seen here appears: <\/P>\n<P><SPAN><IMG title=\"Image of dialog box that appears when script is run\" alt=\"Image of dialog box that appears when script is run\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/september\/hey0902\/hsg-09-02-09-01.jpg\" width=\"205\" height=\"55\">&nbsp;<BR><\/SPAN><BR>By keeping the dialog box small and unobtrusive, it makes the control easy to use. To use the control, you click the drop-down arrow on the far right of the control. When you do, a calendar that displays the current month appears. (Full disclosure: This post was written in August, so this <EM>did <\/EM>display the current month when I was writing this post.) This is seen here: <\/P>\n<P><SPAN><IMG title=\"Image of calendar displaying current month\" border=\"1\" alt=\"Image of calendar displaying current month\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/september\/hey0902\/hsg-09-02-09-02.jpg\" width=\"174\" height=\"151\"><A href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/september\/hey0902\/hsg-09-02-09-02.jpg\"><FONT face=\"Segoe\"><\/FONT><\/A><\/SPAN> <\/P>\n<P>When you pick a date from the calendar, the selected date that is displayed in the Windows form will change. This is seen here: <\/P>\n<P><SPAN><IMG title=\"Image of the selected date changing\" alt=\"Image of the selected date changing\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/september\/hey0902\/hsg-09-02-09-03.jpg\" width=\"205\" height=\"55\"> <BR><\/SPAN><\/P>\n<P>Once you click the <B>Close <\/B>button in the upper right corner, the date is submitted back to the script. Simplicity, elegance, and refinement in a small, easy-to-reuse function. <\/P>\n<P>The Get-DatePickerFunction.ps1 script begins by creating a function named <B>Get-DatePicker<\/B>. This function does not accept any parameters. To create the <B>Get-DatePicker<\/B> function, you only need to use the <B>Function<\/B> keyword and specify the name of the function. The function then opens a script block by using the opening curly brackets. This is seen here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">Function Get-DatePicker <BR>{<SPAN>&nbsp;&nbsp; <\/SPAN><\/FONT>\n<P><\/SPAN>Now you will need to load the <B>System.Windows.Forms<\/B> .NET Framework assembly. This assembly is required for Windows PowerShell to provide access to the .NET Framework classes in the <B>System.Windows.Forms<\/B> .NET Framework namespace. By default the <B>System.Windows.Forms<\/B> assembly is not loaded and the classes from the <B>System.Windows.Forms<\/B> .NET namespace are not available. Many of the graphical classes that Windows PowerShell can use reside in the <B>System.Windows.Forms<\/B> namespace (but not all of them). The use of the <B>LoadWithPartialName<\/B> static method from the <B>System.Reflection.Assembly<\/B> .NET Framework class was discussed <A title=\"yesterday\" href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/09\/01\/hey-scripting-guy-september-1.aspx\">yesterday<\/A>. <\/P>\n<P class=\"MsoNormal\">In Windows PowerShell 2.0, you can use the <B>Add-Type<\/B> cmdlet to load the assembly. This is seen here: <BR><\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">Add-Type \u2013AssemblyName System.windows.forms <\/FONT>\n<P><\/SPAN>The <B>LoadWithPartialName<\/B> static method works on both Windows PowerShell 2.0 and on Windows PowerShell 1.0. The resulting confirmation message from the command is piped to the <B>Out-Null<\/B> cmdlet to avoid cluttering the screen. This is seen here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\"><SPAN>&nbsp;<\/SPAN>[System.Reflection.Assembly]::LoadWithPartialName(&#8220;System.windows.forms&#8221;) | <BR><SPAN>&nbsp;<\/SPAN>Out-Null <\/FONT>\n<P><\/SPAN>A new instance of the .NET Framework <B>Windows.Forms.Form<\/B> class is created by using the <B>New-Object<\/B> cmdlet. The resulting object is stored in the <B>$WinForm<\/B> variable. The <B>Windows.Forms.Form<\/B> .NET Framework class is <A href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.form.aspx\">documented on MSDN,<\/A> and it will be used to host the date picker control that you will create later.<SPAN>&nbsp; <\/SPAN>The <B>Form<\/B> class is created here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\"><SPAN>&nbsp;<\/SPAN>$WinForm = New-Object Windows.Forms.Form<SPAN>&nbsp;&nbsp; <\/SPAN><\/FONT>\n<P><\/SPAN>You can assign any title you wish to for the <B>Windows.Forms.Form<\/B> by assigning a value for the <B>text<\/B> property. This is seen here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\"><SPAN>&nbsp;<\/SPAN>$WinForm.text = &#8220;DatePicker Control&#8221;<SPAN>&nbsp;&nbsp; <\/SPAN><\/FONT>\n<P><\/SPAN>After you have created the <B>Windows.Forms.Form<\/B> class, you will need to create an instance of the <B>System.Drawing.Size<\/B> structure. The <B>System.Drawing.Size<\/B> .NET Framework structure is used to store the width and the height of the rectangular dimensions of the <B>Windows.Forms.Form<\/B>. These dimensions are assigned to the <B>Size<\/B> property of the <B>Form<\/B>. The <B>Size<\/B> dimensions must be supplied as an instance of the <B>System.Drawing.Size<\/B> class. This is seen here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\"><SPAN>&nbsp;<\/SPAN>$WinForm.Size = New-Object Drawing.Size(205,55) <\/FONT>\n<P><\/SPAN>The previous .NET Framework classes are required for most Windows PowerShell projects that create graphical interfaces. To create a date picker, we will need to create an instance of the <B>System.Windows.Forms.DateTimePicker<\/B> control. The <A href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.datetimepicker.aspx\"><FONT face=\"Segoe\">DateTimePicker class<\/FONT><\/A> is documented on MSDN. <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\"><SPAN>&nbsp;<\/SPAN>$DatePicker = New-Object System.Windows.Forms.DateTimePicker<SPAN>&nbsp;&nbsp; <\/SPAN><\/FONT>\n<P><\/SPAN>After the <B>DateTimePicker<\/B> control has been created, it is added to the <B>Controls<\/B> collection of the <B>Form<\/B> class. Once the <B>DateTimePicker<\/B> control is added to the <B>Controls<\/B> collection, the <B>Add_Shown<\/B> method is used to add to the active <B>Form<\/B>. The <B>ShowDialog<\/B> method from the <B>Windows.Forms.Form<\/B> class is used to display the dialog. This is seen here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">$WinForm.Controls.Add($DatePicker) <BR>$WinForm.Add_Shown($WinForm.Activate())<SPAN>&nbsp; <\/SPAN><BR>$WinForm.ShowDialog() | Out-Null<SPAN>&nbsp; <\/SPAN><\/FONT>\n<P><\/SPAN>Once the <B>Form<\/B> with the <B>DateTimePicker<\/B> control is displayed, the value that is returned is the date that is selected from the control. The <B>DateTimePicker<\/B> control value property returns an instance of a <B>DateTime<\/B> class. After the value is returned, the function ends: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\"><SPAN>&nbsp;<\/SPAN>$DatePicker.value <BR>} #end function Get-DatePicker <\/FONT>\n<P><\/SPAN>RS, we are now finished creating the <B>Get-DatePicker<\/B> function. How can we use it? Because it returns a <B>System.DateTime<\/B> structure, <A href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.datetime.aspx\"><FONT face=\"Segoe\">which is documented on MSDN<\/FONT><\/A>, you can use it the same way you use any other date in Windows PowerShell. In Windows PowerShell 1.0, for example, you might want to use the <B>Get-DatePicker<\/B> function to allow you to choose the beginning date to peruse the event logs. In your code, you store the date that is returned from the <B>Get-DatePicker<\/B> function into a variable called <B>$dte<\/B>. You then use the <B>Get-EventLog<\/B> cmdlet to retrieve all of the events from the application log on your local computer. You next pipe the resulting event log entries to the <B>Where-Object<\/B> cmdlet that sorts through the events based upon a <B>timeWritten<\/B> property value that is greater than the date value stored in the <B>$dte<\/B> variable. This is seen here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">$dte = [datetime](Get-DatePicker) <\/FONT><\/P><\/SPAN>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">Get-EventLog -LogName application | <\/FONT><\/P><\/SPAN>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">Where-Object { $_.timeWritten -gt $dte } <\/FONT>\n<P><\/SPAN>The above command, which is at the bottom of the Get-DatePickerFunction.ps1 script, returns the event log entries seen here: <\/P>\n<P><SPAN><IMG title=\"Image of event log entries returned\" alt=\"Image of event log entries returned\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/september\/hey0902\/hsg-09-02-09-04.jpg\" width=\"600\" height=\"481\"><A href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/september\/hey0902\/hsg-09-02-09-04.jpg\"><FONT face=\"Segoe\"><\/FONT><\/A><\/SPAN> <\/P>\n<P>If you are running Windows PowerShell 2.0, it is even easier to search the event log (and it can also be targeted at a remote computer by using the <B>\u2013computername<\/B> parameter) because there is an <B>after<\/B> parameter. This functionality serves two purposes. It filters at the log level instead of returning everything to Windows PowerShell to make the <B>Where-Object<\/B> do the work, and also it makes writing the script code easier. This simplified syntax is seen here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">Get-EventLog -LogName application -After [datetime](Get-Datepicker) <\/FONT>\n<P><\/SPAN>RS, we are taking a five-minute break from the meeting. I need to head downstairs and make some <A href=\"http:\/\/en.wikipedia.org\/wiki\/Earl_Grey_tea\"><FONT face=\"Segoe\">Earl Grey tea<\/FONT><\/A>, grab an <A href=\"http:\/\/en.wikipedia.org\/wiki\/Anzac_biscuit\"><FONT face=\"Segoe\">ANZAC biscuit<\/FONT><\/A>, and get back upstairs so that I can jump back on the conference call. Thanks for a great question! <\/P>\n<P>Join us tomorrow as Graphical Windows PowerShell Week continues. If you want to know what we will be discussing tomorrow, follow us on <A href=\"http:\/\/www.twitter.com\/scriptingguys\/\">Twitter<\/A> or <A href=\"http:\/\/www.new.facebook.com\/home.php#\/group.php?gid=5901799452\">Facebook<\/A>. If you have any questions, send e-mail to <A href=\"mailto:scripter@microsoft.com\"><FONT face=\"Segoe\">scripter@microsoft.com<\/FONT><\/A> or post on the <A href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\">Official Scripting Guys Forum<\/A>. See you tomorrow. Until then, keep on scripting. <\/P>\n<P><B><SPAN><BR>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/SPAN><\/B> <\/P>\n<P><FONT size=\"3\" face=\"Segoe\"><\/FONT>&nbsp;<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Share this post: Hey, Scripting Guy! I hate typing dates. There are several ways of typing dates, and they are all a pain. I do not like having to type the numbers and the whacks, and I do not like having to spell out month names, or attempting to remember if it is month first [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[71,3,4,45],"class_list":["post-52553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-graphical","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Share this post: Hey, Scripting Guy! I hate typing dates. There are several ways of typing dates, and they are all a pain. I do not like having to type the numbers and the whacks, and I do not like having to spell out month names, or attempting to remember if it is month first [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/52553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=52553"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/52553\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=52553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=52553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=52553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}