none
Export CSV PowerShell Script

    Question

  • Hi,

    I have below code. It gives me correct result . But I want to export this result in .csv file as a column order.

    $x = Get-SPOSite
    foreach ($y in $x)
         {
             Write-Host $y.Url -ForegroundColor "Yellow"
            $z = Get-SPOSiteGroup -Site $y.Url
             foreach ($a in $z)
                 {
                     $b = Get-SPOSiteGroup -Site $y.Url -Group $a.Title
                     Write-Host $b.Title -ForegroundColor "Cyan"
                     $b | Select-Object -ExpandProperty Users
                     Write-Host 
                }
        }


    Can any one help me...

    Thanks..

    Tuesday, April 04, 2017 2:42 PM

All replies

  • Use the export-csv cmdlet to export the desired variable: https://technet.microsoft.com/en-us/library/ee176825.aspx?f=255&MSPPError=-2147217396
    Tuesday, April 04, 2017 4:30 PM
  • In code where I need to change.
    Tuesday, April 04, 2017 5:05 PM
  • lol ok. Not quite sure which variable you want, but fine, probably:

    $x = Get-SPOSite
    foreach ($y in $x)
         {
             Write-Host $y.Url -ForegroundColor "Yellow"
            $z = Get-SPOSiteGroup -Site $y.Url
             foreach ($a in $z)
                 {
                     $b = Get-SPOSiteGroup -Site $y.Url -Group $a.Title
                     $b | export-csv c:\spositegroups.csv
                }
        }

    Tuesday, April 04, 2017 7:27 PM