I have a CSV showing some VM stats for each dept, but I would like to add a simple plain text line between each dept for ease of reading. Any help is greatly appreciated.
Here is some of the powershell script:
Connect-VIServer $VC -Credential $Cred
$date=Get-Date -format "yyyy-MMM-dd"
$datetime=Get-Date
$filelocation="/var/www/Reports/Overview/Overview-v2-$date.htm"
$csvfilelocation="/var/www/Reports/Overview/CSV/Overview-v2-$date.csv"
$HDReport = Get-VM $HDVMs | Select-Object Name,@{N="Datastore";E={$_.ExtensionData.Config.Files.VmPathName.Split(']')[0].TrimStart('[')}},VMHost,UsedSpaceGB,MemoryGB,NumCPU | Sort-Object -Property Name,Datastore
$HDReport | Export-Csv -Append -path $csvfilelocation
Here's the current CSV:
https://pasteboard.co/9zJ7YB9Dd7EE.png
You could do
Connect-VIServer $VC -Credential $Cred
$date=Get-Date -format "yyyy-MMM-dd"
$datetime=Get-Date
$filelocation="/var/www/Reports/Overview/Overview-v2-$date.htm"
$csvfilelocation="/var/www/Reports/Overview/CSV/Overview-v2-$date.csv"
$HDReport = Get-VM $HDVMs |
Select-Object Name,
@{N="Datastore";E={$_.ExtensionData.Config.Files.VmPathName.Split(']')[0].TrimStart('[')}},VMHost,UsedSpaceGB,MemoryGB,NumCPU |
Sort-Object -Property Name,Datastore
$HDReport |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
Datastore = $_.Datastore
VMHost = $_.VMHost
UsedSpaceGB = $_.UsedSpaceGB
MemoryGB = $_.MemoryGB
NumCPU = $_.NumCPU
})
New-Object -TypeName PSObject -Property ([ordered]@{
Datastore = ''
VMHost = ''
UsedSpaceGB = ''
MemoryGB = ''
NumCPU = ''
})
} | Export-Csv -Append -path $csvfilelocation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Then it would no longer be a CSV file.
I would add a field for 'department' and then add the correct dept. name to each row.
Where is the department name coming from?
You could do
Connect-VIServer $VC -Credential $Cred
$date=Get-Date -format "yyyy-MMM-dd"
$datetime=Get-Date
$filelocation="/var/www/Reports/Overview/Overview-v2-$date.htm"
$csvfilelocation="/var/www/Reports/Overview/CSV/Overview-v2-$date.csv"
$HDReport = Get-VM $HDVMs |
Select-Object Name,
@{N="Datastore";E={$_.ExtensionData.Config.Files.VmPathName.Split(']')[0].TrimStart('[')}},VMHost,UsedSpaceGB,MemoryGB,NumCPU |
Sort-Object -Property Name,Datastore
$HDReport |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
Datastore = $_.Datastore
VMHost = $_.VMHost
UsedSpaceGB = $_.UsedSpaceGB
MemoryGB = $_.MemoryGB
NumCPU = $_.NumCPU
})
New-Object -TypeName PSObject -Property ([ordered]@{
Datastore = ''
VMHost = ''
UsedSpaceGB = ''
MemoryGB = ''
NumCPU = ''
})
} | Export-Csv -Append -path $csvfilelocation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference