Tuesday, June 02, 2020

Converting csv to excel

Using the useful powershell module importExcel
I could use this to import folder with csv-files to a excelfil for more easy viewing for common users.
Use commented install-module line for first run.


#Install-Module ImportExcel -scope CurrentUser
Import-Module importexcel
$inputFilePath = "C:\temp\csvFiles"
$outputFilePath = "C:\temp\csvFiles\myExcel.xlsx"
$files = get-childitem -Path $inputFilePath -Filter "*.csv" #|select -First 1
if (Test-Path $outputFilePath) { Remove-Item -Path $outputFilePath -Force }
foreach ($file in $files) {
#for files with naming standard myfile_sheetname.csv
$sheetName = $file.name.split("_")[-1].split(".")[0]
write-output "exporting $($file.name)..."
$collection = import-csv -Path $file.FullName
$collection |export-excel -Path $outputFilePath -WorksheetName $sheetName -AutoSize -TableName $sheetName
}
References: https://github.com/dfinke/ImportExcel

Powershell and Uptimerobot

Uptimerobot can be quite tedious when you need to update many monitors at once. For example say you bought the license for Uptimerobot and n...