0

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 "user1@mytenant.com","user2@mytenant.com","user3@mytenant.com" -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,122DevProject@mytenant.onmicrosoft.com,"user1@mytenant.onmicrosoft.com";"user2@mytenant.onmicrosoft.com";"user3@mytenant.onmicrosoft.com",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.

0
1

The type for -Owners parameter should be String[].

You could try the below script:

 {
    [String[]]$owners= $row.OWNERS.replace('"','').split(";")
 New-PnPSite -Type TeamSite -Title $row.DisplayName -Alias $row.Alias -Description $row.DisplayName -Owners $owners -Lcid 1033
}

The $owners value should be like this:

enter image description here

2
  • Thank you @Michael but when I tried this it didn't add users to the Group. Group was empty. – Pradip R. Aug 25 '20 at 10:07
  • Hi, I just tested on my end. This worked for me. Users are added to the Ownwers Group. What's the value of $ownwes? Please check my updated answer, the value should be like that. – Michael Han_MSFT Aug 27 '20 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.