sql - Exporting data onto a csv file or output via email using array -
i have powershell script have written, works well. problem have requirement save results onto database, want email results well. thought couple of options, finding difficult, easy way out thought of export result csv attach csv email.
the code below inside loop.
$sql = " insert dbo.tb_checks ([servername],[directory],[directoryfile] ,[filecreationdate]) select '$servername', '$filepath', '$filename', '$filedate'" invoke-sqlcmd2 -serverinstance $dbserver -database $database -query $sql select '$servername', '$filepath', '$filename', '$filedate' | export-csv $outfilename -append the csv file gets generated, no data.
another idea thought of have data stored in array, loop through/spit out entire content of array in email.
can please ?
the reason csv empty because aren't feeding array can work with. headers use in script? has no idea, it's having random stuff thrown @ it. change last line this:
new-object psobject -property @{server=$servername;filepath=$filepath;filename=$filename;filedate=$filedate} | export-csv $outfilename -append -notypeinformation assuming variables set right should output file want.
if want make table , put in email make empty array before loop, like:
$looparray = @() <start of loop> $looparray += new-object psobject -property @{server=$servername;filepath=$filepath;filename=$filename;filedate=$filedate} $looparray | export-csv $outfilename -append -notypeinformation <end of loop> then afterwards have array work has data in csv stored , can injected email.
Comments
Post a Comment