SharePoint Online: PowerShell kullanarak Kullanıcı Profili Özelliklerini CSV'ye aktarın
Gereksinim: Tüm Kullanıcı Profillerini ve Özelliklerini SharePoint Online'dan bir CSV Dosyasına aktarın.
SharePoint Online: PowerShell kullanarak Kullanıcı Profillerini CSV'ye aktarın
Kullanıcı profilleri bireyler hakkında iş unvanları, departmanları, iletişim bilgileri ve daha fazlası dahil olmak üzere çok çeşitli bilgiler içerir. Bazen kullanıcı profili özelliklerini SharePoint Online ortamından dışarı aktarmamız gerekir. PowerShell ile bu çok kolaydır ve bu blog yazısında, kullanıcı profili özellik değerlerini SharePoint Online'ınızdan CSV formatına nasıl aktaracağınızı göstereceğim.
PowerShell kullanarak SharePoint Online'da kullanıcı profillerini nasıl dışarı aktaracağınız aşağıda açıklanmıştır:
#Load SharePoint CSOM 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"
Function Export-SPOUserProfileProperties()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $CSVPath
)
Try {
#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Delete the CSV report file if exists
if (Test-Path $CSVPath) { Remove-Item $CSVPath }
#Get all Users
$Users = $Ctx.Web.SiteUsers
$Ctx.Load($Users)
$Ctx.ExecuteQuery()
Write-host "Total Number of Profiles Found:"$Users.count -f Yellow
#Get User Profile Manager
$PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Ctx)
#Array to hold result
$UserProfileData = @()
Foreach ($User in $Users)
{
Write-host "Processing User Name:"$User.LoginName
#Get the User Profile
$UserProfile = $PeopleManager.GetPropertiesFor($User.LoginName)
$Ctx.Load($UserProfile)
$Ctx.ExecuteQuery()
if($UserProfile.Email -ne $Null)
{
#Send Data to object array
$UserProfileData += New-Object PSObject -Property @{
'User Account' = $UserProfile.UserProfileProperties["UserName"]
'Full Name' = $UserProfile.UserProfileProperties["PreferredName"]
'E-mail' = $UserProfile.UserProfileProperties["WorkEmail"]
'Department' = $UserProfile.UserProfileProperties["Department"]
'Location' = $UserProfile.UserProfileProperties["Office"]
'Phone' = $UserProfile.UserProfileProperties["WorkPhone"]
'Job Title' = $UserProfile.UserProfileProperties["Title"]
}
}
}
#Export the data to CSV
$UserProfileData | Export-Csv $CSVPath -Append -NoTypeInformation
write-host -f Green "User Profiles Data Exported Successfully to:" $CSVPath
}
Catch {
write-host -f Red "Error Exporting User Profile Properties!" $_.Exception.Message
}
}
#Call the function
$SiteURL="https://crescent-my.sharepoint.com"
$CSVPath="C:\Temp\UserProfiles.csv"
Export-SPOUserProfileProperties -SiteURL $SiteURL -CSVPath $CSVPath
Bu PowerShell betiği, bir site koleksiyonundan kullanıcı profillerini alır ve bunları bir Excel dosyasına (CSV) aktarır. Peki tüm site koleksiyonları için kullanıcı profillerini nasıl çıkaracağız? SharePoint Online'daki Kullanıcı Profili Hizmeti Uygulamasına bağlanmanın ve CSOM kullanarak kiracıdaki tüm kullanıcılar için tüm kullanıcı profili özelliklerini almanın doğrudan bir yolu yoktur. Ya tüm Site Koleksiyonlarını yinelemeniz (ve aralarındaki kopyaları kaldırmanız!) ya da SharePoint Online'a bağlanmak ve tüm kullanıcı profillerini almak için Web Hizmetlerini kullanmanız gerekecektir.
Ancak daha iyi bir yol var: SharePoint Online CSOM ve Azure AD Connect Kombinasyonunu kullanalım!
Ön Koşullar: SharePoint Online İstemci SDK'sına (https://www.microsoft.com/en-us/download/details.aspx?id=42038) ve Azure Active Directory Modülüne ( Bu betiği kullanmadan önce istemci makinenize https://technet.microsoft.com/en-us/library/dn975125.aspx) yükleyin!
PowerShell, SharePoint Online'daki Tüm Kullanıcı Profili Özelliklerini Dışa Aktaracak
Belirli bir site koleksiyonuna ait kullanıcı profillerini almak yerine kiracının tüm kullanıcı profillerini alalım ve kullanıcı profili özelliklerini bir CSV dosyasına aktaralım.
#Load SharePoint CSOM 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"
#Import Azure AD Module
Import-Module MSOnline
Function Export-AllUserProfiles()
{
param
(
[Parameter(Mandatory=$true)] [string] $TenantURL,
[Parameter(Mandatory=$true)] [string] $CSVPath
)
Try {
#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($TenantURL)
$Ctx.Credentials = $Credentials
#Delete the CSV report file if exists
if (Test-Path $CSVPath) { Remove-Item $CSVPath }
#Get all Users
Connect-MsolService -Credential $Cred
$Users = Get-MsolUser -All | Select-Object -ExpandProperty UserPrincipalName
Write-host "Total Number of Profiles Found:"$Users.count -f Yellow
#Get User Profile Manager
$PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Ctx)
#Array to hold result
$UserProfileData = @()
Foreach ($User in $Users)
{
Write-host "Processing User Name:"$User
#Get the User Profile
$UserLoginName = "i:0#.f|membership|" + $User #format to claims
$UserProfile = $PeopleManager.GetPropertiesFor($UserLoginName)
$Ctx.Load($UserProfile)
$Ctx.ExecuteQuery()
if($UserProfile.Email -ne $Null)
{
#Send Data to object array
$UserProfileData += New-Object PSObject -Property @{
'User Account' = $UserProfile.UserProfileProperties["UserName"]
'Full Name' = $UserProfile.UserProfileProperties["PreferredName"]
'E-mail' = $UserProfile.UserProfileProperties["WorkEmail"]
'Department' = $UserProfile.UserProfileProperties["Department"]
'Location' = $UserProfile.UserProfileProperties["Office"]
'Phone' = $UserProfile.UserProfileProperties["WorkPhone"]
'Job Title' = $UserProfile.UserProfileProperties["Title"]
}
}
}
#Export the data to CSV
$UserProfileData | Export-Csv $CSVPath -Append -NoTypeInformation
write-host -f Green "User Profiles Data Exported Successfully to:" $CSVPath
}
Catch {
write-host -f Red "Error Exporting User Profile Properties!" $_.Exception.Message
}
}
#Call the function
$TenantURL="https://crescent.sharepoint.com"
$CSVPath="C:\Temp\UserProfiles.csv"
Export-AllUserProfiles -TenantURL $TenantURL -CSVPath $CSVPath
Bu komut dosyası, tüm kullanıcı profillerini SharePoint Çevrimiçi Kiracısından aşağıdaki özelliklere sahip bir CSV Dosyasına çıkarır:
- Hesap
- Ad Soyad
- E-Posta
- Departman
- Konum,
- İş unvanı
Ek özellikler ekleyebilirsiniz. PowerShell Betiği tarafından oluşturulan Rapor çıktısı şöyledir:
Tüm Kullanıcı Profili Özelliklerini Dışa Aktarmak için PnP PowerShell
Her kullanıcı profilinin tüm özelliklerini bir CSV raporuna çıkarmak için PnP PowerShell'i burada bulabilirsiniz:
#Config Variables
$AdminSiteURL = "https://crescent-admin.sharepoint.com"
$CSVPath = "C:\Temp\UserProfiles.csv"
Try {
#Connect to AzureAD
Connect-AzureAD | Out-Null
#Get All Users of the Domain from AzureAD
$AllUsers = Get-AzureADUser -All:$True -Filter "UserType eq 'Member'"
Write-host "Total Number of User Profiles Found:"$AllUsers.Count
#Connect to PnP Online
Connect-PnPOnline -Url $AdminSiteURL -UseWebLogin
#Iterate through All Users
$Counter = 1
$UserProfileData = @()
ForEach($User in $AllUsers)
{
Write-host "`nGetting User Profile Property for: $($User.UserPrincipalName)" -f Yellow
#Get the User Property value from SharePoint
$UserProfile = Get-PnPUserProfileProperty -Account ($User.UserPrincipalName)
#Get User Profile Data
$UserData = New-Object PSObject
ForEach($Key in $UserProfile.UserProfileProperties.Keys)
{
$UserData | Add-Member NoteProperty $Key($UserProfile.UserProfileProperties[$Key])
}
$UserProfileData += $UserData
$Counter++
Write-Progress -Activity "Getting User Profile Data..." -Status "Getting User Profile $Counter of $($AllUsers.Count)" -PercentComplete (($Counter / $AllUsers.Count) * 100)
}
#Export the data to CSV
$UserProfileData | Export-Csv $CSVPath -NoTypeInformation
write-host -f Green "User Profiles Data Exported Successfully to:" $CSVPath
}
Catch {
write-host -f Red "Error Getting User Profile Property!" $_.Exception.Message
}
Kullanıcı profili özelliklerini SharePoint Online'dan dışarı aktarmak, kullanıcı verilerini yönetmek ve değiştirmek için yararlı olabilir. Bu makalede özetlenen adımları izleyerek kullanıcı profili özelliklerini dışa aktarabilir ve kullanıcı profili verilerini inceleyebilirsiniz.
