I'd like to be able to get the results in columns in CSV.
Get-DrsClusterGroup | Select @{N="GroupName";E={$_.Name}}, Cluster, @{N="Member";E={$_.Member.Name}} | Export-Csv -Path $fileName -NoTypeInformation -UseCulture
Send-MailMessage -From "vca002@inc.com" -To "my_email@inc.com" -Attachments $fileName -Subject "AffinityRules" -SmtpServer "smtp.inc.com"
The snippet here almost does the same thing, it produces the result but the Member property, when exported in CSV, adds the values all in one cell for a group. Could we have one member per cell in columns?
Due to a "feature" in Export-Csv it uses the first row of the exported array to determine how many columns there will be in the CSV.
This can be bypassed by sorting the array in such a way that the row with the most members comes first.
Get-DrsClusterGroup -PipelineVariable group |
ForEach-Object -Process {
$obj = [ordered]@{
GroupName = $group.Name
Cluster = $group.Cluster.Name
}
$i = 1
$group.Member| ForEach-Object -Process {
$obj.Add("Member$($i)",$_.Name)
$i++
}
New-Object -TypeName PSObject -Property $obj
} | Sort-Object -Property {(Get-Member -InputObject $_ -MemberType NoteProperty).Count} -Descending |
Export-Csv -Path $fileName -NoTypeInformation -UseCulture
Send-MailMessage -From "vca002@inc.com" -To "my_email@inc.com" -Attachments $fileName -Subject "AffinityRules" -SmtpServer "smtp.inc.com"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Due to a "feature" in Export-Csv it uses the first row of the exported array to determine how many columns there will be in the CSV.
This can be bypassed by sorting the array in such a way that the row with the most members comes first.
Get-DrsClusterGroup -PipelineVariable group |
ForEach-Object -Process {
$obj = [ordered]@{
GroupName = $group.Name
Cluster = $group.Cluster.Name
}
$i = 1
$group.Member| ForEach-Object -Process {
$obj.Add("Member$($i)",$_.Name)
$i++
}
New-Object -TypeName PSObject -Property $obj
} | Sort-Object -Property {(Get-Member -InputObject $_ -MemberType NoteProperty).Count} -Descending |
Export-Csv -Path $fileName -NoTypeInformation -UseCulture
Send-MailMessage -From "vca002@inc.com" -To "my_email@inc.com" -Attachments $fileName -Subject "AffinityRules" -SmtpServer "smtp.inc.com"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That worked. I wouldn't have been able to come up with this. Thanks again LucD