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

can't pass a file's LastWriteDate to a function

$
0
0

I just want to pass a file's LastWriteDate to a function.  I've tried two different ways. Passing the whole file's info and just passing the file's LastWriteDate,, as shown by my two different functions.

$backedUpDirectoryPath="\\nas1\bu\DeptShares\Daily"

functionpassAllFileInfo(

   [Parameter(Mandatory=$true)][System.IO.FileInfo]$allFileInfo)

{

   Write-Host$allFileInfo.lastWriteTime

}

functionpassOnlyLastWriteTime(

   [Parameter(Mandatory=$true)][System.DateTime]$onlyLastWriteTime)

{

   Write-Host$onlyLastWriteTime

}

$latest=Get-ChildItem-Path$backedUpDirectoryPath|Sort-ObjectLastWriteTime-Descending|Select-Object-First1

Write-Host$latest.lastWriteTime

passAllFileInfo-$latest

passAllFileInfo-$latest.LastWriteTime

which inexplicably yields:

2/21/2014 1:12:54 AM

12/31/1600 6:00:00 PM

12/31/1600 6:00:00 PM

Very frustrating because I can’t seem to pass a simple file date to a function.  I tried these two different ways but in both cases it seems to wipe out all such information.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



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