Created
February 2, 2016 21:47
-
-
Save mikecasas/00461cc6a9852e5c064c to your computer and use it in GitHub Desktop.
CSV manipulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cls | |
function DefaultEmptyDate($anydate) { | |
if ($anydate) { | |
$a=[datetime]$anydate | |
} else { | |
$a= [datetime]"1/1/1900" | |
} | |
return $a.ToShortDateString() | |
} | |
#Set-Location($env:userprofile + '\Documents') | |
$path='\\chnfs3\unixnt$\SmartStreams\Payroll\' | |
Set-Location($path) | |
$list = Import-CSV $pwd\empcdf.csv | | |
Select @{Name="employeeId";Expression={$_."EMP ID"}}, | |
@{Name="retiredOn";Expression={$_."RETIRED DATE"}}, | |
@{Name="calendarDays";Expression={$_."CAL DAYS"}} | |
$lines=@() | |
$list.foreach{ | |
$item=New-Object PSObject -prop @{ | |
employeeId=[int]::Parse($_."employeeId"); | |
calendarDays=[int]::Parse($_."calendarDays"); | |
retiredOn=[datetime](DefaultEmptyDate($_."retiredOn")); | |
} | |
$lines +=$item | |
} | |
$lines | export-csv -notype $pwd\empcdfShort.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment