I am running a script which export the data to CSV file and I re-import the same file to remove the duplicate rows and them export them.
- Need to clean the up the first file after the script execution
- Is it possible to store the data in an object without export and import for manipulating the data
&{foreach($role in Get-VIRole){
Get-VIPrivilege -Role $role -ErrorAction SilentlyContinue |
Select @{N="Role";E={$role.Name}},@{N="Assigned Privileges";E={$_.ID}}
}} | Export-Csv C:\Scripts\Permission.CSV -NoTypeInformation -UseCulture
&{foreach($row in (Import-Csv C:\Scripts\Permission.CSV -UseCulture)){
if($prevRole -and $row.Role -eq $prevRole){
$role = ""
}
Else{
$role = $prevRole = $row.Role
}
New-Object PSObject -Property @{
Role = $role
"Assigned privileges" = $row."Assigned Privileges"
}
}} | Select "Role","Assigned Privileges" | Export-CSV