Not sure how to use -UseCulture parameter. I don't think the csv is corrupt because the script is creating the csv on its 1st run. Here is the full code. The intent is to run the script daily so I can see growth patterns and growth rate. You can ignore the "clusterdetails" I copied from another script that reports on clusters and I just haven't changed that part so its more logical. Feel free to comment on anything else I can do to clean up my code as I am just getting started with powershell.
$csvreport= @()
$today=Get-Date-formatd
$i=0
$VMNum=0
$data=0
$VMs=Get-VM
$VMCount=$VMs.count
$ofile="C:\Temp\DataGrowth.csv"
# Check for file / Read old file if exists
if (Test-Path$ofile){
$csvreport=type$ofile | ConvertFrom-Csv
}
foreach($VMin$VMs) {
#Get-Vm | Foreach-object {
$entity=$VM
$VMNum++
#Progress Bar
$Activity="Collecting Stats for VM"
Write-Progress-Activity"Collecting stats for VM $entity" -Status"VM $VMNum of $VMCount"-PercentComplete (($i/$VMCount)*100)
$data+=$VM.UsedSpaceGB
$i++
}
$data= [math]::round(($data), 5)
# Creates List of Custer Details
$clusterdetails="" |select-object Collection_Date,Total_Size,VM_Count
$clusterdetails.Collection_Date=$today
$clusterdetails.Total_Size=$data
$clusterdetails.VM_Count=$VMCount
$csvreport+=$clusterdetails
$csvreport |export-csv-NoTypeinformation$ofile
$csvreport=""
######################################################