PowerShell kullanarak SharePoint Kullanıcı Profili Nasıl Silinir?


Genellikle aşağıdaki olaylardan herhangi biri meydana geldiğinde SharePoint kullanıcı profilleri silinir:

  • Active Directory'de kullanıcı hesabı silindi
  • Hesap devredışı
  • Kullanıcı Profili Hizmeti Uygulama Bağlantısı değiştirildi veya yeniden oluşturuldu
  • Hesap AD'de yeniden oluşturuldu veya SharePoint Kullanıcı Profili senkronizasyon bağlantısının parçası olmayan bir kuruluş biriminin dışına taşındı

Bazen SharePoint kullanıcı profillerini manuel olarak silmeniz gerekebilir. Bu blog yazısı, SharePoint'te bir kullanıcı profilini silmek için PowerShell'in nasıl kullanılacağını gösterecektir.

SharePoint'te bir Kullanıcı Profilini silmek için PowerShell:

İşte SharePoint'te bir kullanıcı profilini silmek için PowerShell:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "https://mypage.crescent.com"
$AccountName="Crescent\Sherif"

#Get Objects
$ServiceContext  = Get-SPServiceContext -site $SiteURL
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)

#Get the User Profile
$UserProfile = $UserProfileManager.GetUserProfile($AccountName) 

#remove user profile
$UserProfileManager.RemoveUserProfile($AccountName);  

PowerShell kullanarak SharePoint'teki Tüm Kullanıcı Profillerini Silme

Bir senaryoda kullanıcı profili mağazasını temizlemem gerekiyor. Kullanıcı profili deposunda birçok profil bulunmasına rağmen bunlar SharePoint 2013 Merkezi yönetiminde gösterilmiyordu. Bu nedenle, yetim/bozuk kullanıcı profillerinin Merkezi yönetimden silinmesi mümkün değildir. Tüm kullanıcı profillerini kaldırmak için şu PowerShell betiğini kullanın:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "https://mypage.crescent.com"

#Get Objects
$ServiceContext  = Get-SPServiceContext -site $SiteURL
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)

#Ger all User Profiles
$UserProfiles = $UserProfileManager.GetEnumerator()
 
# Loop through user profile
Foreach ($Profile in $UserProfiles) 
{
    write-host Removing User Profile: $Profile["AccountName"] 
    
    #Remove User Profile
    $UserProfileManager.RemoveUserProfile($profile["AccountName"])
}

Belirli bir alan adına ait Tüm Kullanıcı Profillerini Alıp silebilir miyim? Elbette:


$DomainPrefix = "Crescent"
$UserProfiles = $UserProfileManager.GetEnumerator()| Where-Object {$_.Accountname -like "$($DomainPrefix)\*"}

İlgili makaleler