다음을 통해 공유


Quick way to set up Office 365 tenant for testing

The following article describes few useful Powershell cmdlets to set up Office 365 tenant for testing purposes. If you prefer to directly copy-paste instead of reading, please scroll down to the Summary of the Cmdlets

Prerequisites

Microsoft Online Services Sign-in Assistant
Windows Azure Active Directory Module for Windows PowerShell
SharePoint Online Management Shell
Office 365 tenant

Steps

Connect to Services

Connect to your Office 365 subscription:

Connect-MsolService

Connect to SharePoint Online

Connect-SPOService -Url https://TENANT-admin.sharepoint.com

Create users

Since this is merely for testing purposes, the names are irrelevant and I opted for for easily manageable user1, user2, user3, etc. One can also use a .csv file with more original names and import the data using Import-CSV cmdlet.

for($i=1;$i -lt 10; $i++){ new-msoluser -UserPrincipalName ("user"+$i+"@testova365.onmicrosoft.com") -DisplayName "user"  -UsageLocation de -PasswordNeverExpires $true -Password MyPassword -StrongPasswordRequired $false}

Comments:
UPN - the variable $i allows me to create users with unique UPNs: user1, user2, etc.
TESTOVA365 - name of my test tenant. Change it to yours.
DisplayName - in the example every user has the same display name. We could differentiate between by using ("user"+$i) instead of "user"
UsageLocation - we need to set UsageLocation in order to apply the licenses later
PasswordNeverExpires&Password&StrongPasswordRequired - for the ease of use. Of course, such setting is not secure.
    

Assign licenses to users

The following line assumes that there is only one type of subscription on the tenant. 

for($i=1;$i -lt 10; $i++){Set-MsolUserLicense -UserPrincipalName ("user"+$i+"@testova365.onmicrosoft.com") -AddLicenses (Get-MsolAccountSku).ID }

Verify

Get-MsolUser

Create SharePoint sites

One site collection per template

We can create site collections using different templates. The cmdlets below, first get available templates, secondly create site collections based on those templates.

$templates=Get-SPOWebTemplate
foreach($template in $templates){New-SPOSite -Url ("https://testova365.sharepoint.com/sites/"+$template.Name.Substring(0,3)) -Owner t@testova365.onmicrosoft.com -StorageQuota 1 -ResourceQuota 100 -Template $template.Name -Title $template.Title -LocaleId 1033 }

Comments
Get-SPOWebTemplate - retrieves available site templates and saves them in $templates variable for future use
TESTOVA365 - name of my Office 365 tenant. Needs to be changed.
t@testova365.onmicrosoft.com - UPN of my admin user. Please change to yours.
1033 - lcid for English language. If not specified, the site would be created in the default language of the tenant.

Verify

 

One site collection per user

The cmdlets below give each user his own site collection, e.g. to play with. That means that each user administers a different site collection and each site has a different admin.

for($i=1;$i -lt 10; $i++){New-SPOSite -Url ("https://testova365.sharepoint.com/sites/site"+$i) -Owner ("user"+$i+"@testova365.onmicrosoft.com") -StorageQuota 1 -ResourceQuota 100 -Template STS#0 -Title "For testing" -LocaleId 1033 }

Comments:
Testova365 -  name of my Office 365 tenant. Needs to be changed.
STS#0 - Teamsite template for the site collection
1033 - lcid for English language. If not specified, the site would be created in the default language of the tenant.

Summary

In the steps above we have created 10 users and assigned them licenses.  The users are ready to use their mailboxes and all of Office 365 services, like Skype for Business, Yammer or OneDrive for Business. We also created several functional site collections, ready for collaboration between these users.

 

Summary of the cmdlets

In the lines below you need only to change the values for $tenant and $admin to adjust them to your Office365 tenant.

$tenant="testova365"
$admin="t@testova365.onmicrosoft.com"
Connect-MsolService
Connect-SPOService -Url ("https://"+$TENANT+"-admin.sharepoint.com")
 
for($i=1;$i -lt 10; $i++){ new-msoluser -UserPrincipalName ("user"+$i+"@"+$tenant+".onmicrosoft.com") -DisplayName ("user"+$i) -UsageLocation de -PasswordNeverExpires $true -Password MyPassword -StrongPasswordRequired $false}
for($i=1;$i -lt 10; $i++){Set-MsolUserLicense -UserPrincipalName ("user"+$i+"@"+$tenant+".onmicrosoft.com") -AddLicenses (Get-MsolAccountSku).ID }
 
Get-MsolUser
 
for($i=1;$i -lt 10; $i++){New-SPOSite -Url ("https://"+$tenant+".sharepoint.com/sites/site"+$i) -Owner ("user"+$i+"@"+$tenant+".onmicrosoft.com") -StorageQuota 1 -ResourceQuota 100 -Template STS#0 -Title "For testing" -LocaleId 1033 }

https://c.statcounter.com/11253394/0/5e7c69b2/0/