I am trying to write a PowerShell scripts that accomplishes the following tasks with partial results :
- Retrieving a list of SharePoint sites (including OneDrive sites) that contain a certain word in the url (done) ;
- Using a ForEach-Object to retrieve the list of owners and users of each site (done);
- Exporting these informations in a CSV file (partially done);
My problem is the number 3, I'm trying to make it with one column for the sites URLs, one column for the owner, and the 3rd column with all the users inside, but unfortunately I'm only able to make the csv with the users list inside, here is the code that brought me to this point :
$username = "[email protected]"
$password = "password" | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
$Tenanturl = "https://domain-admin.sharepoint.com/"
# Connessione all'account Admin SharePoint
Connect-SPOService -Url $TenantUrl -Credential $credential
Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Owner -like 'WordIWantToFilter'" |
ForEach-Object {
Get-SPOUser -Site $_.Url
} |
Select-Object -Property LoginName,UserType |
Export-Csv -Path "C:\Users\User\Desktop\SharePoint_Sites_List.csv" -NoTypeInformation
The result is a CSV file with LoginName,"UserType" in the cell A1, and the related info in the other rows.
What I am trying to accomplish : First column for the sites URLs, Second column for the owner of the sites, and the 3rd column with all the users of each site inside.
I know I am missing a lot of stuff, but I'm not a developer whatsoever :), these are some of the links I used to make this code,
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/export-csv?view=powershell-7 https://techcommunity.microsoft.com/t5/sharepoint/list-all-site-collection-admins-powershell/m-p/264135
what should I look for ? I'm looking for tips or even just little pieces of code, thanks
,
as the field separator. You could tryExport-Csv -Path "C:\Users\User\Desktop\SharePoint_Sites_List.csv" -NoTypeInformation -UseCulture
. - AdminOfThings