Help wth Script Format

Hi I am hoping someone can help me with the below script?

I want to create a script that exports Teams detials to an excel spreadsheet that will show the following details. Team Name, Team Description, No of Owners, Owners, No of Channels and Channels.

The script I am running produces all this but I would like to try and put it in a csv format with each team details on 1 line. So the owners etc would be ‘Owner1, Owner2, Etc’ in 1 cell and Channels would be 'Channel1, Channel2, etc) .

The script is the below I am struggling how to add the Owner and Teams Channels to appear as 1 entity. (Hope that makes sense). I believe I need to add all the owners to its own array (seperated by a ‘,’) and the same for the Teams channels but struggling on how to do this.

This is the script that brings back the detials.

$allteams = Get-Team
$object = @()

foreach ($t in $allteams) {

$members = Get-TeamUser -GroupId $t.GroupId

$owner = Get-TeamUser -GroupId $t.GroupId -Role Owner

$channels = Get-TeamChannel -GroupId $t.GroupId 

$object += New-Object -TypeName PSObject -Property ([ordered]@{

    'Team Name'= $t.DisplayName
    'Description' = $t.Description
    'No Of Owners' = $owner.count
    'Owners' = $owner.User
    'Members' = $members.count
    'No Of Channels' = $channels.count
    'Channels' = $channels.displayname -join "`r`n"
 
    })

}
Write-Output $object | Out-File C:\Temp\TeamsDetails.txt

Once I have found how to add the team owners and channels to its own array I should then be able to export the report to a csv rather than a text file.

Thanks for any help in advance.

Thanks

Dom

Ok have just had a change in the script as realised I need to remove the join in the teamschannel statement which then shows them as one string.

However when exporting to excel for Owners and Teams it just says System.Object in the cell.

Any ideas on why this is showing as this?

ok its kind of fallen into place now and have sorted this. Just incase it helps anyone else the final script is below which shows all owners and teams channels as 1 row per spreadsheet. I just needed to add -join ‘,’ at the end of the owners and teamschannel statement.

$allteams = Get-Team
$object = @()

foreach ($t in $allteams) {

$members = Get-TeamUser -GroupId $t.GroupId

$owner = Get-TeamUser -GroupId $t.GroupId -Role Owner

$channels = Get-TeamChannel -GroupId $t.GroupId 

$object += New-Object -TypeName PSObject -Property ([ordered]@{

    'Team Name'= $t.DisplayName
    'Description' = $t.Description
    'No Of Owners' = $owner.count
    'Owners' = $owner.User -join ','
    'Members' = $members.count
    'No Of Channels' = $channels.count
    'Channels' = $channels.displayname -join ','
 
    })

}
Write-Output $object | export-csv c:\temp\TeamsDetails.csv -NoTypeInformation

1 Like

Did you know that you can edit your own already existing posts if you want change something or if you want to correct something? You don’t have to create a new one every time you have something to add. :wink:

1 Like