SOLVED

how to i add export command to the below script

Highlighted
Occasional Contributor

how to i add export command to the below script

 

$siteURL = "https://litwareinc.sharepoint.com/sites/finance"
$x = Get-SPOSiteGroup -Site $siteURL
foreach ($y in $x)
    {
        Write-Host $y.Title -ForegroundColor "Yellow"
        Get-SPOSiteGroup -Site $siteURL -Group $y.Title | Select-Object -ExpandProperty Users
        Write-Host
    }

 

6 Replies
Highlighted

You might want to give a bit more detail on what you are trying to do? Do you want to export the output to an .txt file?

Highlighted

export the output to a csv file

 

thanks

Highlighted

this script returns a site collection groups and members of those groups

 

i just want to export the results to csv

Highlighted
Solution

How about:

 

($siteURL = "https://litwareinc.sharepoint.com/sites/finance"
$x = Get-SPOSiteGroup -Site $siteURL
foreach ($y in $x)
    {
        Get-SPOSiteGroup -Site $siteURL -Group $y.Title | Select-Object -ExpandProperty Users
    })| Export-Csv -Path c:\temp\test.csv

 

Highlighted

Try this script

 

$siteURL = "https://litwareinc.sharepoint.com/sites/finance"
$x = Get-SPOSiteGroup -Site $siteURL
$GroupList = @()


foreach ($y in $x)
    {
       
        
        $users= Get-SPOSiteGroup -Site $siteURL -Group $y.Title | Select-Object -ExpandProperty Users
                   $Group = "" | Select "Groupname","Userslist"
                   $UsersList = ''
                      foreach($user in $users)
                      {
                         If($UsersList) 
                           {
                             $UsersList=$UsersList + ";" + $user.ToString()
                           } 
                         Else 
                         {
                          $UsersList=$user.ToString()
                         }
                      }
                      $Group.Groupname = $y.Title
                     $Group.Userslist = $UsersList
                     $GroupList+= $Group

        
    }
$GroupList |Export-csv C:\csv\groupwithusers.csv -NoTypeInformation
Highlighted

Get-MsolUser -All | Where-Object {$_.Domain -eq "centricaplc.onmicrosoft.com"} | Export-CSV c:\support\cloud.csv

 

please help am stuck