-
Notifications
You must be signed in to change notification settings - Fork 0
/
OD4BBuilkDeploy.ps1
116 lines (83 loc) · 3.29 KB
/
OD4BBuilkDeploy.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#Provision OneDrive/PersonalSite for Users that need it provisioned
#This runs slowly so run this overnight
#Install-Module -Name AzureAD
Import-Module AzureAD
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
#update and store password as necessary
$logfile2 = 'c:\temp\OneDrivesProvisioned.txt';
#Must be SharePoint Administrator URL
$webUrl = "https://[ORGANIZATION SITE]-admin.sharepoint.com";
#MySite web URL
$mysitewebUrl = "https://[ORGANIZATION SITE]-my.sharepoint.com";
$username = "GlobalAdmin@contoso.com";
#Credential for Office 365
$mycreds = Get-Credential -Message "Office 365 Credential" -UserName $username
#Connect to msolservice to query users
Connect-AzureAD -credential $mycreds;
$filter = 'accountEnabled eq true';
$licenseduserList = Get-AzureADUser -All $True -Filter $filter | Where { ($_.AssignedLicenses -ne $Null -and $_.AssignedLicenses.Count -gt 0) -and !($_.UserPrincipalName -like "8*" -or $_.UserPrincipalName -like "9*")} | Sort-Object UserPrincipalName
Disconnect-AzureAD
Write-Host "OneDrive Provisioning";
#Connect to SharePoint Online to Provision OneDrive
Connect-SPOService -Url $webUrl -Credential $mycreds
Write-Host "Connected to site and Provision Search Started: $webUrl" -ForegroundColor Green;
#Test view all sites
#Get-SPOSite
if ($licenseduserList)
{
$usercount = 1;
$usersToProvision = @();
$usersprovisioned = @();
foreach ($eachuser in $licenseduserList)
{
#Run OneDrive/PersonalSite Provisioning in batches of 10
if ($usercount -gt 10)
{
Write-Host "Batch Provisioning OneDrive for users:";
Write-Host "Users Needing Provision:";
$usersToProvision;
Request-SPOPersonalSite -UserEmails $usersToProvision;
$usersToProvision = @();
$usercount = 1;
}
#To enqueue
$onedriveuser = [string]$($eachuser.UserPrincipalName);
Write-Host $usercount
#$usersToProvision += $onedriveuser;
$spouser1 = $null;
try
{
#ignore the current user if no error
$spouser1 = Get-SPOUser -Site $mysitewebUrl -LoginName $onedriveuser
$usersprovisioned += $onedriveuser;
}
catch
{
#users not provisioned with onedrive get caught
$usersToProvision += $onedriveuser;
Add-Content $logfile2 $onedriveuser;
$usercount++;
#Write-Host $onedriveuser
}
}
#Run last batch
if ($usercount -gt 1)
{
Write-Host "Batch Provisioning OneDrive for users:";
Write-Host "Users Needing Provision:";
$usersToProvision;
Request-SPOPersonalSite -UserEmails $usersToProvision;
$usersToProvision = @();
$usercount = 1;
}
}
else
{
Write-Host "No Users to Provision";
}
Disconnect-SPOService;
Write-Host "One Drive Provisioning Completed" ;
#to Test Provisioning succeeded wait at least a few hours
#Login to Office 365 using an account then hit the url below replacing username as desired
#replace @ symbol and . with underscores in the UserPrincipalName
#https://[ORGANIZATION SITE]-my.sharepoint.com/personal/USERPRINCIPALNAME