$infile = 'ee-29074271.txt'
$data =Get-Content $infile | ConvertFrom-Csv -Header number,Name,index,index2,computer,date
$now = get-date -Format ("yyyy-MM-dd HH:mm:ss")
foreach( $dat in $data)
{
$dat.date = $now
}
$data | Export-csv -NoTypeInformation -Path temp.dat
$dat = get-content temp.dat | select-object -Skip 1 | set-content "temp2.dat"
Remove-Item $infile
Rename-Item -Path 'temp2.dat' -NewName $infile -Force
Remove-Item -Path temp.dat
get-content $infile | Format-List
function Get-Data
{
<#
.SYNOPSIS
Changes date to current date/time
.DESCRIPTION
The Function will change the date of a specific type of data file to the current date/time
.EXAMPLE
Get-Data -infile c:\data\data.txt
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$false, Position=0)]
[System.String] $infile = 'ee-29074271.txt'
)
$data = Get-Content $infile | ConvertFrom-Csv -Header number,Name,index,index2,computer,date
$now = (get-date -Format ("yyyy-MM-dd HH:mm:ss"))
foreach ($dat in $data) { $dat.date = $now }
$data | Export-csv -NoTypeInformation -Path temp.dat
$dat = get-content temp.dat | select-object -Skip 1 | set-content "temp2.dat"
Remove-Item $infile
Rename-Item -Path 'temp2.dat' -NewName $infile -Force
Remove-Item -Path temp.dat
$dat = get-content $infile
foreach($data in $dat){write-verbose $data}
}
Open in new window