VMware Cloud Community
Jstrat31
Enthusiast
Enthusiast

Need help totaling columns for csv reports I'm creating

Sorry for the noob question but my Powershell skills are a bit rusty.

I've created the below script to get all the client subfolders in our main client service provider folder, and make a csv report for each VM in the client sub folder

It also creates a folder on our data server with the year and month to put all the reports in for accounting purposes.

Everything is working great and the reports are going where they need to go... My only issue is I need to total the "NumCpu","MemoryGB","TotalHDSiceGB", and "SpaceUsedGB" columns at the bottom for the reports.
I've typically a DYI guy, but I'm not fluent enough with Powershell to do what I want.

Thanks for any help!!!!

#create current Year Folder

$folderyear = "$(Get-Date -Format yyy)"

$path = "c:/temp"

$destinationyear = "$path/$folderyear/"

If(!(test-path -path $destinationyear))

{

      New-Item -Path $path -Name $folderyear -ItemType Directory

}

else

{

Write-Host "The given folder path $directoyPath already exists";

}

#create current Month folder

$foldermonth = "$(Get-Date -format MMMM)"

$destinationmonth = "$destinationyear/$foldermonth/"

If(!(test-path -path $destinationmonth))

{

      New-Item -Path $destinationyear -Name $foldermonth -ItemType Directory

}

else

{

Write-Host "The given folder path $destinationmonth already exists";

}

#Generate VM resource reports from client VM folders

$clients = Get-Folder pca01_hx_customer2_vm | get-folder -NoRecursion

foreach ($vm in $clients)

{

$vms = @(Get-Folder $vm | Get-VM)

$vms | Select-Object Name,NumCpu,MemoryGB,

@{n="TotalHDSizeGB"; e={(Get-HardDisk -VM $_ |Measure-Object -Sum CapacityGB).Sum}},

@{ n="SpaceUsedGB"; e={[math]::round( $_.UsedSpaceGB )}},

@{N="Folder";E={$_.Folder.Name}} | Export-Csv -NoTypeInformation -path "$destinationmonth\$vm.csv"  }

Jason Hartley VMware Systems Specialist "Develop the skill of sensing problems when they are still small and taking care of them before they become intractable"—Robert Greene http://privatecloudky.com/
0 Kudos
1 Reply
LucD
Leadership
Leadership

After you created the content for $vms, it would require adding another line with the 'totals' to that array.

For a similar example, see Re: Total CPU GHZ,Total CPU Cores, Total Memory and Total VM's


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos