Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Help required to manipulate the data without exporting the output twice

$
0
0

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.

  1.      Need to clean the up the first file after the script execution
  2.      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


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>