$BulkLoadFolder = "C:\Projects\Sntrax\Bulkload\FilesToFix"
$Folder = "C:\FilesToFix\"
$filesList = Get-ChildItem -Path $Folder -Filter *.csv | select fullname | ForEach-Object { $_.FullName }
foreach($file in $filesList)
{
$newfile = $file.Replace("FilestoFix","FilestoFix\fixed")
#Get lastwritetime for the filename
$LastWriteDateTime = Get-ItemPropertyValue -Path $file -Name LastWriteTime
#Import file and Export
Import-Csv $file | ForEach-Object {
if ($_.Field1.Trim() -eq '') {
$_.Field1 = '--'
}
if ($_.Field2.Trim() -eq '') {
$_.Field2 = '--'
}
$_
} | Export-Csv $newfile -NoTypeInformation -Force
Set-ItemProperty -Path $newfile -Name LastWriteTime -Value $LastWriteDateTime
}
Monday, 8 February 2021
Maintain timestamp of CSV File
We were having a scenario, where we had to fix few CSV field issues. But, we also wanted to retain timestamp. We used below script to fix the CSV and maintain the timestamp.
Subscribe to:
Post Comments (Atom)
How to Handle SSIS Database movement from one environment to another
Below are the steps to follow the movement of SSISDB from one environment to another: -- opening the existing Database master key in S...
-
We can execute SSIS packages deployed in SSIS Catalog using stored procedure based approach as given below: DECLARE @execution_id I...
-
This blog post talks about my problems with installing SQL SERVER 2008 Developer Edition in my Windows XP box. After two failed attemp...
-
When we want to see how many files are using a specific keyword, we can use below powershell script to do this. This will be helpful if we w...
No comments:
Post a Comment