Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

intermittent : The term 'get-date' is not recognized as the name of a cmdlet, function, script file, or operable program.

$
0
0

I have developed a batch harness whereby all scheduled tasks (W2012) invoke a common powershell script that acts as a wrapper to all our housekeeping jobs.

The first step in the wrapper is to create a Transcript file using following code

if ($Host.name -ne "Windows PowerShell ISE Host") # Transcript does not work within ISE
{
$timestamp = (get-date -format "yyyy-MM-dd-HH-mm-ss.fff")
$path = "c:\corp\$timestamp" + "_$pid.txt"
Start-Transcript -path $path -append
}

As expected the folder contains files with timestamp & pid in name

08/08/2013  11:00 AM            14,388 2013-08-08-11-00-01.158_1620.txt
08/08/2013  11:00 AM            12,506 2013-08-08-11-00-01.485_936.txt
08/08/2013  11:00 AM            12,994 2013-08-08-11-00-01.735_9328.txt
08/08/2013  11:00 AM            12,024 2013-08-08-11-00-01.766_8624.txt
08/08/2013  11:00 AM            13,902 2013-08-08-11-00-01.860_1756.txt
08/08/2013  11:01 AM            15,142 2013-08-08-11-01-31.392_10120.txt
08/08/2013  05:00 AM            14,982 _1692.txt

However note the last file, it has a zero length date time value in the name

The error recorded by PowerShell is

get-date : The term 'get-date' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Corp\Powershell\DMPRun-ScheduledTask.ps1:171 char:18
+    $timestamp = (get-date -format "yyyy-MM-dd-HH-mm-ss.fff")
+                  ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (get-date:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

IE get-date has failed and returned a zero length field as the timestamp

Can anyone think of a good reason why get-date would fail intermittently?

Do I have to code defensively for base Powershell functions?


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>