当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何使用 PowerShell 删除 SharePoint 用户配置文件?

作者:精品下载站 日期:2024-12-14 14:02:37 浏览:14 分类:玩电脑

如何使用 PowerShell 删除 SharePoint 用户配置文件?


通常,当发生以下任何事件时,SharePoint 用户配置文件将被删除:

  • 用户帐户已在 Active Directory 中删除
  • 帐户已被禁用
  • 用户配置文件服务应用程序连接已更改或重新创建
  • 在 AD 中重新创建帐户或将帐户移出不属于 SharePoint 用户配置文件同步连接的 OU

有时,您可能需要手动删除 SharePoint 用户配置文件。这篇博文将向您展示如何使用 PowerShell 删除 SharePoint 中的用户配置文件。

[玩转系统] 如何使用 PowerShell 删除 SharePoint 用户配置文件?

使用 PowerShell 删除 SharePoint 中的用户配置文件:

以下是用于删除 SharePoint 中的用户配置文件的 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 删除 SharePoint 中的所有用户配置文件

在一个场景中,我需要清理用户配置文件存储。尽管用户配置文件存储中存在许多配置文件,但它们并未显示在 SharePoint 2013 管理中心中。因此,无法从管理中心删除孤立/损坏的用户个人资料。 要删除所有用户配置文件,请使用以下 PowerShell 脚本:


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"])
}

我可以从特定域获取所有用户配置文件并将其删除吗?当然:


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

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯