I was trying to create new Site collection in my SharePoint online tenant with O365 group. So I have come across following commands from PnP PowerShell.
New-PnPSite
allows us to create O365 group with Site Collection. So I was trying to create multiple site collection from CSV. That CSV does contain information about Owners of the site. So when I try following command after authenticating to PnPOnline
single line code works as below:
New-PnPSite -Type TeamSite -Title "0ABC Test" -Alias "0abctest" -Description "some desc" -Owners "[email protected]","use[email protected]","[email protected]" -Lcid 1033
Above code will create new O365 group and also adds those user mentioned as a owner of the group. This command will also create site collection.
But when I try it by reading Owners from CSV file as below (Sample CSV):
DisplayName,Alias,EmailAddresses,OWNERS,AccessType
122 Dev Test,122DevProject,[email protected],"[email protected]";"[email protected]";"[email protected]",Private
new site never adds owner, it always shows empty. Below is my PS Code:
foreach ($row in $table) #$table is my CSV object
{
[array]$owners = $row.OWNERS.split(";")
[string]$stringOwners = $null
$stringOwners = '"{0}' -F ($owners -join '",')
$stringOwners = $stringOwners.Replace('""', '"')
$stringOwners = $stringOwners.Trim(',')
New-PnPSite -Type TeamSite -Title $row.DisplayName -Alias $row.Alias -Description $row.DisplayName -Owners $stringOwners -Lcid 1033
}
So my question is how can we add multiple user for New-PnPSite
reading owners from CSV file. Is this really possible? Am I missing something here?
Any help would be much appreciated.