{"id":52413,"date":"2009-09-22T03:01:00","date_gmt":"2009-09-22T03:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/09\/22\/hey-scripting-guy-how-can-i-check-for-the-presence-or-absence-of-a-text-file\/"},"modified":"2009-09-22T03:01:00","modified_gmt":"2009-09-22T03:01:00","slug":"hey-scripting-guy-how-can-i-check-for-the-presence-or-absence-of-a-text-file","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-check-for-the-presence-or-absence-of-a-text-file\/","title":{"rendered":"Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?"},"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\/22\/hey-scripting-guy-september-21-2009.aspx&amp;title=Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?\" 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\/22\/hey-scripting-guy-september-21-2009.aspx&amp;bookmark_title=Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?\" 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\/22\/hey-scripting-guy-september-21-2009.aspx&amp;;title=Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?\" 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\/22\/hey-scripting-guy-september-21-2009.aspx&amp;title=Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?\" 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\/22\/hey-scripting-guy-september-21-2009.aspx&amp;t=Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?\" 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\/22\/hey-scripting-guy-september-21-2009.aspx&amp;ti=Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?\" 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\/22\/hey-scripting-guy-september-21-2009.aspx&amp;title=Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?\" 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\/22\/hey-scripting-guy-september-21-2009.aspx&amp;title=Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?\" 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\/22\/hey-scripting-guy-september-21-2009.aspx&amp;title=Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?\" 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\/22\/hey-scripting-guy-september-21-2009.aspx&amp;title=Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?\" 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\/22\/hey-scripting-guy-september-21-2009.aspx&amp;title=Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?\" 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\/22\/hey-scripting-guy-september-21-2009.aspx&amp;t=Hey, Scripting Guy! How Can I Check for the Presence or Absence of a Text File?\" 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\">&nbsp;<\/P>\n<P class=\"MsoNormal\"><SPAN><SPAN><IMG 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\"><\/SPAN><\/SPAN>Hey, Scripting Guy! We use text files in special folders to determine if we have performed an operation on a computer. For example, we might install a piece of software on a computer. While it is possible to query the <B>Win32_Product<\/B> WMI class to determine if the software has been installed or to query the registry, it is much easier to simply see if a text file is present in a specific folder. If the text file is present, we have installed the software. This is an idea I had a long time ago when working with Systems Management Server (SMS). I would do a query to see if the text file exists. <\/P>\n<P class=\"MsoNormal\">I would like to have a Windows PowerShell script that will check for the existence of a text file. If the file does not exist, I would like to create the text file. If the file does exist, I would like to be notified. I could then modify such a script to work with my existing infrastructure. Can you provide me with a sample Windows PowerShell script that will do this?<\/P>\n<P class=\"MsoNormal\">&#8212; EC<\/P>\n<P><FONT size=\"3\"><IMG 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\"><\/FONT><\/P>\n<P class=\"MsoNormal\">Hello EC, Microsoft Scripting Guy Ed Wilson here. <\/P>\n<P class=\"MsoNormal\">A long time ago, back when I was a consultant in <A href=\"http:\/\/en.wikipedia.org\/wiki\/Cincinnati\"><FONT face=\"Segoe\">Cincinnati, Ohio, in the United States<\/FONT><\/A>, I did a number of SMS 1.0 deployments. After I got my <A href=\"http:\/\/bit.ly\/4wf8nt\"><FONT face=\"Segoe\">Microsoft Certified Trainer<\/FONT><\/A> (MCT) certification, I even taught SMS classes. Over the years, I continued to work with SMS up to version 2.0. It was a fun and interesting product. One day, I hope to begin working with <A href=\"http:\/\/www.microsoft.com\/systemcenter\/en\/us\/default.aspx\">Microsoft System Center<\/A> (the replacement for SMS) because it looks like a pretty cool product. So, EC, I know exactly what you are talking about when you mention looking for the presence of a file. We used to call such a file a <I>canary file<\/I> back in the days when I was working with SMS. I was looking around in the Hey, Scripting Guy! archives, and found the <A href=\"http:\/\/bit.ly\/hU1S3\"><FONT face=\"Segoe\">How Can I Determine If a File Exists and If It does, Exit the Script?<\/FONT><\/A> article. <SPAN>&nbsp;<\/SPAN>This article was written using the <B>FileSystemObject<\/B> and VBScript. You could duplicate it in Windows PowerShell using the <B>FileSystemObject<\/B>, but there is no reason to do this because Windows PowerShell has the <B>Test-Path<\/B> cmdlet that is designed to check for the existence of things. <\/P>\n<P class=\"MsoNormal\">EC, I wrote the DetermineIfFileExists.ps1 script for you. It will check the existence of a specific file, and if the file does not exist, it will create the file for you. Inside the file, it will record the current time. If the file does exist, the script displays a small message on the Windows PowerShell console, and then the script will exit. The complete DetermineIfFileExists.ps1 script is seen here. <\/P>\n<P class=\"CodeBlockScreenedHead\"><STRONG>DetermineIfFileExists.ps1<\/STRONG><\/P>\n<P class=\"CodeBlockScreened\"><SPAN><FONT><FONT face=\"Lucida Sans Typewriter\">$path = &#8220;c:\\fso\\IwasHere.txt&#8221;<BR><BR>If(-not(Test-Path -path $path))<BR><SPAN>&nbsp; <\/SPAN>{<BR><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>New-Item -Path $path -ItemType file -Value $(Get-Date) -force<BR><SPAN>&nbsp; <\/SPAN>}<BR>Else<BR><SPAN>&nbsp;<\/SPAN>{ &#8220;File exists&#8221; ; exit }<\/FONT><\/FONT><\/SPAN><\/P>\n<P class=\"MsoNormal\">The DetermineIfFileExists.ps1 script begins by using the <B>$path<\/B> variable to hold the path to a specific file. The file in this case is called <B>IwasHere.txt<\/B>, and it should be located in the FSO folder on the <B>C:\\<\/B> drive. As seen in the following image, the text file does not exist:<\/P>\n<P class=\"Fig-Graphic\"><IMG title=\"Image of IwasHere.text file not yet in C:\\Fso\" alt=\"Image of IwasHere.text file not yet in C:\\Fso\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/september\/hey0922\/hsg-09-22-09-01.jpg\" width=\"600\" height=\"268\"><\/P>\n<P class=\"MsoNormal\"><BR>The line of code that holds the path to the text file is seen here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">$path = &#8220;c:\\fso\\IwasHere.txt&#8221;<\/FONT><\/SPAN><\/P>\n<P class=\"MsoNormal\">The <B>Test-Path<\/B> cmdlet is used to determine if the text file exists. When using the <B>Test-Path<\/B> cmdlet, it is important to realize that it only returns true or false. As seen here, the <B>Test-Path<\/B> cmdlet is used to determine if there is a file named <B>1234.txt<\/B> in the <B>C:\\fso<\/B> folder. The <B>1234.txt<\/B> file does in fact exist (as shown in the image above), and therefore the <B>Test-Path<\/B> cmdlet returns true: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">PS C:\\&gt; Test-Path -Path C:\\fso\\1234.txt<BR>True<BR>PS C:\\&gt;<\/FONT><\/SPAN><\/P>\n<P class=\"MsoNormal\">If you want to evaluate the returned Boolean value, you can use the <B>If<\/B> statement to evaluate the true\/false values that are returned by the <B>Test-Path<\/B> cmdlet. This technique is shown here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">PS C:\\&gt; If((Test-Path -Path C:\\fso\\1234.txt) -eq $true) { &#8220;The file exists&#8221; }<BR>The file exists<BR>PS C:\\&gt;<\/FONT><\/SPAN><\/P>\n<P class=\"MsoNormal\">A better approach to dealing with the Boolean value returned value by the <B>Test-Path<\/B> cmdlet is to not use the equality operator (<B>-eq<\/B>). Because the return value is true\/false, you can say (in effect), \u201cIf the file exists, do something.\u201d This is shown here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">PS C:\\&gt; If(Test-Path -Path C:\\fso\\1234.txt) { &#8220;The file exists&#8221; }<BR>The file exists<BR>PS C:\\&gt;<\/FONT><\/SPAN><\/P>\n<P class=\"MsoNormal\">The \u201cif the file exists\u201d technique works great if you are interested in the existence of the file, but what if you want to know if the file does not exist? You could go back to specifically evaluating the true\/false condition and look for false as shown here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">PS C:\\&gt; If((Test-Path -Path C:\\fso\\1234.txt) -eq $false) { &#8220;File does notexist&#8221; }<BR>PS C:\\&gt;<\/FONT><\/SPAN><\/P>\n<P class=\"MsoNormal\">But a better approach is to use the <B>\u2013not<\/B> operator inside the <B>If\/Test-Path<\/B> condition. This is the approach that was taken with the DetermineIfFileExists.ps1 script. The code is shown here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">If(-not(Test-Path -path $path))<\/FONT><\/SPAN><\/P>\n<P class=\"MsoNormal\">The one thing to keep in mind is the placement of the parentheses. Because you want to evaluate the return code from the <B>Test-Path<\/B> cmdlet, you need to ensure the <B>Test-Path<\/B> cmdlet runs first. To do this, it is placed inside a set of parentheses. After the Boolean return value is returned, the <B>\u2013not<\/B> operator is evaluated. If the file does not exist, the file will be created by using the <B>New-Item<\/B> cmdlet, which is used to create new items. <\/P>\n<P class=\"MsoNormal\">The type of item it will create depends upon the Windows PowerShell provider that is used. In this example, because you are working with the file system, you are using the <B>FileSystem<\/B> provider. The Windows PowerShell <B>FileSystem<\/B> provider is capable of creating two different types of items\u2014a file or a directory. Because of this, you must specify a value for the <B>\u2013ItemType<\/B> parameter. The <B>\u2013path<\/B> parameter is used to tell the cmdlet where to create the new item. The path can be local, or it can be located on a remote computer by using a <A href=\"http:\/\/en.wikipedia.org\/wiki\/Universal_Naming_Convention\"><FONT face=\"Segoe\">Universal Naming Convention (UNC) path<\/FONT><\/A> such as \\\\remotecomputername\\remotesharename\\filename.<SPAN>&nbsp; <\/SPAN>To illustrate using UNC, first ping a remote computer. After determining that the remote computer is available, use the <B>New-Item<\/B> cmdlet to create a file. After the file has been created, use the <B>Get-ChildItem<\/B> cmdlet to ensure that the file is present on the remote computer. The use of UNC paths is seen here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">PS C:\\&gt; ping hyperv<BR><BR>Pinging HyperV.NWTraders.Com [192.168.1.100] with 32 bytes of data:<BR>Reply from 192.168.1.100: bytes=32 time=1ms TTL=128<BR>Reply from 192.168.1.100: bytes=32 time=1ms TTL=128<BR>Reply from 192.168.1.100: bytes=32 time=1ms TTL=128<BR>Reply from 192.168.1.100: bytes=32 time&lt;1ms TTL=128<BR><BR>Ping statistics for 192.168.1.100:<BR><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),<BR>Approximate round trip times in milli-seconds:<BR><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>Minimum = 0ms, Maximum = 1ms, Average = 0ms<BR>PS C:\\&gt; New-Item -Path \\\\hyperv\\c$\\fso\\myfile.txt -Force -ItemType file<BR><BR><BR><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>Directory: \\\\hyperv\\c$\\fso<BR><BR><BR>Mode<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>LastWriteTime<SPAN>&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>Length Name<BR>&#8212;-<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&#8212;&#8212;&#8212;&#8212;-<SPAN>&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&#8212;&#8212; &#8212;-<BR>-a&#8212;<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>9\/15\/2009<SPAN>&nbsp;&nbsp; <\/SPAN>5:20 PM<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>0 myfile.txt<BR><BR><BR>PS C:\\&gt; Get-ChildItem -Path &#8216;\\\\hyperv\\c$\\fso&#8217;<BR><BR><BR><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>Directory: \\\\hyperv\\c$\\fso<BR><BR><BR>Mode<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>LastWriteTime<SPAN>&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>Length Name<BR>&#8212;-<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN>&#8212;&#8212;&#8212;&#8212;-<SPAN>&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&#8212;&#8212; &#8212;-<BR>-a&#8212;<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>9\/15\/2009<SPAN>&nbsp;&nbsp; <\/SPAN>5:20 PM<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>0 myfile.txt<BR><BR><BR>PS C:\\&gt;<\/FONT><\/SPAN><\/P>\n<P class=\"MsoNormal\">In the DetermineIfFileExists.ps1 script the <B>New-Item<\/B> cmdlet is used to create a new file. The initial value (the contents of the newly created text file) is created by using a subexpression to force the execution of the <B>Get-Date<\/B> cmdlet. The <B>\u2013force<\/B> parameter is used to create the folder that is expressed in the path, if the folder does not exist. This portion of the script is seen here inside a pair of curly brackets (also known as the script block):<\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\"><SPAN>&nbsp; <\/SPAN>{<BR><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>New-Item -Path $path -ItemType file -Value $(Get-Date) -force<BR><SPAN>&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/P>\n<P class=\"MsoNormal\">If the file already exists, the string \u201cFile exists\u201d is displayed on the Windows PowerShell console, and the script is exited. To exit a running Windows PowerShell script, you use the <B>exit<\/B> command. To combine two separate commands on the same line, you separate the commands with a semicolon. This part of the script is seen here: <\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\">Else<\/FONT><\/SPAN><\/P>\n<P class=\"CodeBlock\"><SPAN><FONT face=\"Lucida Sans Typewriter\"><SPAN>&nbsp;<\/SPAN>{ &#8220;File exists&#8221; ; exit }<\/FONT><\/SPAN><\/P>\n<P class=\"MsoNormal\">When the script runs, the <B>IwasHere.txt<\/B> file is created in the <B>C:\\fso<\/B> directory, as seen here:<\/P>\n<P class=\"Fig-Graphic\"><IMG title=\"Image of IwasHere.txt file created in C:\\fso directory\" alt=\"Image of IwasHere.txt file created in C:\\fso directory\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/september\/hey0922\/hsg-09-22-09-02.jpg\" width=\"600\" height=\"268\"><\/P>\n<P class=\"Fig-Graphic\">&nbsp;<\/P>\n<P class=\"MsoNormal\">The <B>IwasHere.txt<\/B> file contains the date and time the script was run. This can be seen here:<\/P>\n<P class=\"Fig-Graphic\"><IMG title=\"Image of date and time script was run\" alt=\"Image of date and time script was run\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/september\/hey0922\/hsg-09-22-09-03.jpg\" width=\"347\" height=\"217\"><\/P>\n<P class=\"Fig-Graphic\">&nbsp;<\/P>\n<P class=\"MsoNormal\">EC, this concludes looking at the DetermineIfFileExists.ps1 Windows PowerShell script. The <B>Test-Path<\/B> cmdlet can be extremely useful when attempting to determine if a file exists or not. The only trick to using it is realizing you do not need to directly evaluate the Boolean value that is returned by the cmdlet. Because there is also a registry provider inside Windows PowerShell, you can also use the <B>Test-Path<\/B> cmdlet to determine if a registry key exists or not. It is really cool and powerful stuff. <\/P>\n<P class=\"MsoNormal\">If you want to know exactly what we will be covering tomorrow, follow us on <A href=\"http:\/\/www.twitter.com\/scriptingguys\/\" target=\"_blank\">Twitter<\/A> or <A href=\"http:\/\/www.facebook.com\/group.php?gid=5901799452\" target=\"_blank\">Facebook<\/A>. If you have any questions, send e-mail to us at <A href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/A> or post your questions on the <A href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\" target=\"_blank\">Official Scripting Guys Forum<\/A>. See you tomorrow. Until then, peace.<\/P>\n<P><FONT face=\"Segoe\"><STRONG>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/STRONG><\/FONT>&nbsp;<\/P>\n<P>&nbsp;<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Share this post: &nbsp; Hey, Scripting Guy! We use text files in special folders to determine if we have performed an operation on a computer. For example, we might install a piece of software on a computer. While it is possible to query the Win32_Product WMI class to determine if the software has been installed [&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":[38,3,12,45],"class_list":["post-52413","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-files","tag-scripting-guy","tag-storage","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Share this post: &nbsp; Hey, Scripting Guy! We use text files in special folders to determine if we have performed an operation on a computer. For example, we might install a piece of software on a computer. While it is possible to query the Win32_Product WMI class to determine if the software has been installed [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/52413","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=52413"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/52413\/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=52413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=52413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=52413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}