Search This Blog

Monday, February 8, 2016

Some Useful powershell scripts


Power shell scripts:

#1 Read file names from csv file using pipe delimiter and copy files to with new name to new destination

C:\Temp\finals.csv - csv file
FileName - source file
NewFileName - new name and destination for file

$csv = Import-Csv L:\DataMigration\CalRad\Reports_finals.csv '|' -Header FileName,NewFileName
foreach ($line in $csv) {    If ((Test-Path $line.FileName)){ Copy-Item -path $line.FileName -Destination $line.NewFileName } }



#2  Get all of the pdf full file paths
      execute application using full file path as a command argument.


  $items = Get-ChildItem "L:\DataMigration\CalRad\LegacyData\LegacyReports\Scanned_Docs" -Filter *.pdf 
  foreach ($item in $items) { L:\DataMigration\CalRad\PDFToImage\PDFToImages.exe $item.FullName 140}


#3) import csv file pipe delimited with 4 columns
      copy file to new location using 3rd parameter as source location and 4th parameters as destination path and file name.


$csv = Import-Csv L:\DataMigration\CalRad\LegacyData\LegacyReports\Scanned_Docs.csv '|' -Header Accession,Type,FileName,NewFileName
   foreach ($line in $csv) {    If ((Test-Path $line.FileName)){ Copy-Item -path $line.FileName -Destination $line.NewFileName } }

No comments: