Wednesday, June 24, 2015

Write to CSV file using power shell

Being share point administrator it was always one part of job to generate reports for multiple site , With help of object model reference it's easy to pull data using powershell and dumping this into CVS is always good idea for further reporting


This piece of code can be use to generate power shell output in CSV format however not limited to share point . It;s very generic example to show how data can be populated in CSV


Powers hell code :


#Write to CSV File
$fileName = "FilePath\Sample1.csv"
#write header of file 
"Site Collection `t Site `t List" > $fileName
for ($i -eq 0; $i -le 50; $i++)
{
    "SiteCollection"+$i +"`t"+ "Site"+$i +"`t"+"List"+$i >>$filename
}
write-host "Report complated please refer file :" $filename

No comments:

Post a Comment