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

PSObject modify value for new object

$
0
0

Hi

I'm creating a new PSObject, as a replacement for exporting data to csv and then reimporting. Reason is i need to do some compare on LastWriteTime on the Date only, not the time. I have this part to create the object.

        $NewFile = @()
            Foreach ($file in $AllFiles)
                {
                #Lookups
                    $LastWriteDate = $file |  select @{Name="LastWriteTime";Expression= {"{0:yyyy}-{0:MM}-{0:dd}" -f ([DateTime]$_.LastWriteTime)}}
                #Create PSObject
                    $nFile = New-Object PSObject -Property @{
                        FileName         = $file.name
                        BaseName         = $file.BaseName
                        Extension        = $file.extension
                        Parentfolder     = $file.DirectoryName
                        LastWriteTime    = $file.LastWriteTime
                        LastWriteDate    = $LastWriteDate
                    }
                    $NewFile += $nFile
                }


Which does everything right except the LastWriteDate part. I need to return the date only and not as i see now:

Extension LastWriteDate               Parentfolder                                    BaseName           FileName               LastWriteTime      
--------- -------------               ------------                                    --------           --------              -------------      
.PDF      @{LastWriteTime=2012-08-08}

Any idea's ?


/Frederik Leed


Viewing all articles
Browse latest Browse all 21975

Trending Articles



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