در این مقاله نحوه بهروزرسانی انبوه Admin ثانویه برای My Sites یا OneDrive for Business (ODFB) با استفاده از PowerShell را خواهیم دید.
در برخی شرایط، ممکن است لازم باشد مدیر سایت ثانویه را اضافه کنید تا به عنوان بخشی از حاکمیت، به محیط «OneDrive for Business» یک کاربر دسترسی داشته باشید. به طور پیش فرض، هر کاربر به عنوان مدیران مجموعه سایت های اصلی و ثانویه به سایت شخصی خود یا مجموعه سایت ODFB اضافه می شود.
برای مشاهده مدیران مجموعه های سایت برای MySite مراحل زیر را دنبال کنید.
مرکز مدیریت SP - پروفایل های کاربر - مدیریت نمایه کاربر - جستجوی یک کاربر.
هنگامی که کاربری برای حذف علامتگذاری میشود و اگر نمایندگی دسترسی در تنظیمات My Site مرکز مدیریت SP فعال باشد، اقدام پیشفرض انتقال مالکیت به مدیر یا مالک ثانویه (در صورت عدم حضور مدیر) برای در دست گرفتن کنترل است. فایل ها در غیاب کاربر
در برخی موارد، هیچ مدیری و همچنین هیچ مدیر ثانویه ای منصوب نمی شود. در چنین شرایطی، این سایت ها یا ODFB یتیم می شوند و پس از 30 روز (دوره نگهداری پیش فرض) حذف می شوند.
با این حال، همانطور که در صفحه بالا نشان داده شده است، گزینه ای برای فعال کردن My Site Secondary Admin وجود دارد اما این فقط برای My Sites جدید کار می کند . برای سایتهای من که قبلاً ایجاد شدهاند، باید به صورت جداگانه اضافه شود که برای یک یا چند نفر خوب است اما اضافه کردن آن برای همه سخت است.
از اسکریپت زیر برای به روز رسانی انبوه سرپرست ثانویه برای همه سایت های من استفاده کنید.
در سطح بالا، در زیر مراحل انجام شده در اسکریپت آمده است.
- اعلام متغیر (متغیر را با توجه به مستاجر خود پیکربندی کنید)
- به SharePoint Online & Context متصل شوید
- برای بازیابی اطلاعات نمایه، شیء مدیر افراد را ایجاد کنید
- به Azure Active Directory متصل شوید
- دریافت نمایه های کاربر در کد من دو دستور ارائه کرده ام -- یکی برای بازیابی همه کاربران دارای مجوز و دیگری برای واکشی یک کاربر. شما باید کد را بر اساس نیاز خود نظر دهید.
- بارگیری نمایه کاربر با استفاده از مدیر نمایه و بازیابی URL PersonalSpace (URL سایت من)
- مدیریت ثانویه را تنظیم کنید
- صادرات به فایل CSV.
- #Pre-Requisites, Install below modules
- #Sharepoint online Management Shell : https://www.microsoft.com/en-us/download/details.aspx?id=35588
- #Azure Active Directory http://connect.microsoft.com/site1164/Downloads/DownloadDetails.aspx?DownloadID=59185
- #SharePoint Online Client Components SDK https://www.microsoft.com/en-us/download/details.aspx?id=42038
- Clear-Host
- #Specify tenant admin and URL
- $AdminAccount = 'admin@company.com'
- $TenantURL = 'https://company-admin.sharepoint.com'
- #Specify the secondary admin account and the url for the onedrive site
- $Secondaryadmin = 'Secondaryadmin@company.com'
- $MySiteURL = 'https://company-my.sharepoint.com'
- #Use this varable to apply seconday site collection for a specific user
- $User = 'targetuser@company.com'
- #Location to save the report
- $UserProfileOutPut = 'D:\MyWokingFolder\Report\AllProfiles.csv'
- #Attention: sometimes folder path may be 15 or 16. Browse the folder and verify the availability of the dlls
- #Add references to SharePoint online client component assemblies
- Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
- Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
- Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll'
- Write-Host "Loading SharePoint Assemblies..." -ForegroundColor Yellow
- Write-Host "Connecting to SharePoint Online Service and Context..." -ForegroundColor Yellow
- $Password = Read-Host -Prompt 'Please enter your password' -AsSecureString
- $Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $AdminAccount, $Password
- $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminAccount,$Password)
- #Bind to Site Collection
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext($TenantURL)
- $Context.Credentials = $Creds
- Write-Host "Connected to SharePoint Online Context..." -ForegroundColor Yellow
- #Create People Manager object to retrieve profile data
- $PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context) -ErrorAction Inquire
- Write-Host "Loading People Manager..." -ForegroundColor Yellow
- #Connect to Office 365 tenant
- try
- {
- Connect-MsolService -Credential $Credentials -ErrorAction Inquire
- Write-Host "Connected to SharePoint Online Service..." -ForegroundColor Yellow
- }
- catch
- {
- Write-Host "Unable to Connect to SharePoint Online...Existing the Script."
- return
- }
- #Use below code to apply seconday site collection for all licensed users
- $Users = Get-MsolUser -All | where {$_.isLicensed -eq $true}
- #Use below code to apply seconday site collection for a specific user
- #$Users = Get-MsolUser -All | where {$_.UserPrincipalName -eq $User}
- Write-Host "Collecting Users Information from SharePoint Online..." -ForegroundColor Yellow
- $Headings = ""
- $boolCreateHeadings = $true
- Connect-SPOService -Url $TenantURL -Credential $Credentials
- Foreach ($User in $Users)
- {
- $ClaimsUserFormat = 'i:0#.f|membership|'+ $User.UserPrincipalName
- $UserProfile = $PeopleManager.GetPropertiesFor($ClaimsUserFormat)
- $Context.Load($UserProfile)
- $Context.ExecuteQuery()
- #Allow profiles only with PersonalSpace URL
- If ($UserProfile.UserProfileProperties['PersonalSpace'] -ne $null)
- {
- $PersonalSpace = $UserProfile.UserProfileProperties['PersonalSpace'];
- $PersonalSpace = $MySiteURL + $PersonalSpace
- $temp = Set-SPOUser -Site $PersonalSpace -LoginName $secondaryadmin -IsSiteCollectionAdmin $true
- Write-Host "Added secondary admin to the site ($PersonalSpace)"
- if($boolCreateHeadings)
- {
- Write-Host "Loading CSV Headings..." -ForegroundColor Green
- $Headings = '" FirstName "," LastName "," UserName "," PersonalSpace "'
- $Headings -join "," | Out-File -Encoding default -FilePath $UserProfileOutPut
- $boolCreateHeadings = $false
- }
- $Properties = '"' + $UserProfile.UserProfileProperties["FirstName"] + '",' + '"' + $UserProfile.UserProfileProperties["LastName"] + '",' + '"' + $UserProfile.UserProfileProperties["UserName"] + '",' + '"' + $UserProfile.UserProfileProperties["FirstName"] + '",' + '"' + $UserProfile.UserProfileProperties["PersonalSpace"] + '"';
- #Export to CSV.
- $Properties -join "," | Out-File -Encoding default -Append -FilePath $UserProfileOutPut
- Write-Host "User Profile Written to CSV $UserProfileOutPut" -ForegroundColor Yellow
- }
- }
- Write-Host "Successfully assigned seconday site collection admin.All profiles have been Written to $UserProfileOutPut" -ForegroundColor Green
برای اجرای اسکریپت بدون خطا، پیش نیازهای زیر باید رعایت شود.