Hello, I'm trying to get a list of users and groups that are assigned to each vm on a viserver. When I run the following script, and have it output to the screen, I see the permissions for each vm, but when I try to export to csv I get System.Object[] instead of a list of user accounts.
Any help would greatly be appreciated.
$results = @()
$fieldvms = get-vm -server $viserver
ForEach ( $vm in $fieldvms )
{
$cluster = $vm | get-cluster
$vmperms = $vm | Get-VIPermission
$Properties = @{
vm_name = $vm.Name
cluster_name = $cluster.Name
vm_perms = $vmperms.Where({$_.principal -like "corp*"}) | select Principal
}
$Results += New-Object psobject -Property $properties
}
$Results | Select-Object VM_Name, Cluster_Name, VM_Perms | Export-Csv path\file.csv
#Permissions output when trying to export to csv: System.Object[]
The Export-Csv cmdlet can't handle row elements that are arrays.
In that case it shows this System.Object[], indicating it encountered an array.
A simple solution is to use a calculated property and in the Expression part join the elements of the array together into one string.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The Export-Csv cmdlet can't handle row elements that are arrays.
In that case it shows this System.Object[], indicating it encountered an array.
A simple solution is to use a calculated property and in the Expression part join the elements of the array together into one string.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD. I also found that I could use -join ',' to get the output that I need.