0

you can see my question in the title.

One more another question to this situation: Do any of you know, what happens after the MySite-CleanUp-Job runs? In my company there are a lot of users with the "bDelete"-Flag which are still working with their users on the farm. Now i want to delete the "unused"-Profiles manually via PS-Script. I found a lot of solutions:

  • Delete via script from every Site (foreach - site)
  • RemoveUserProfile()
  • RemoveProfile()
  • PersonalSite.Delete()

i am a little bit confused, which one i need to use?! Thanks in advance!!

Leon

0

UserProfileManager.RemoveUserProfile Method: Removes the user profile, quick links, and alert data from the user profile database.

UserProfileManager.RemoveProfile(ProfileBase) Method: Removes the specified user profile from the database.

If you want to delete inactive users in user profiles, we can use the PowerShell below to achieve it.

#PowerShell Script – Delete Inactive User Profiles – SharePoint 2010/2013

#The scripts is distributet "as-is." Use it on your own risk. The author give no warranties, guarantees or conditions.

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

$site = Get-SPSite "<site url>"
$ctx = Get-SPServiceContext $site
$pm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ctx)

$ProfileDB = Get-SPDatabase | ? { $_.Type -eq "Microsoft.Office.Server.Administration.ProfileDatabase"}

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = $ProfileDB.DatabaseConnectionString
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "select NTName,RecordId from UserProfile_Full where bDeleted=1″
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()

Write-host "Total Count: " $DataSet.Tables[0].Rows.Count
Write-Host "Following Inactive Accounts will be deleted !"

foreach($user in $DataSet.Tables[0].Rows)
{
   write-host "Planning to delete :" $user["NTName"] -ForegroundColor Green
   $profile = $pm.GetProfile($user["RecordId"])
    #To enable delete operation remove comment out for below line
    #$pm.RemoveProfile($profile)
    #write-host $user["NTName"] is deleted!!! -ForegroundColor Red
}
write-host "Operation Completed !"

Refer to: Delete inactive users in user profiles

The complete guide to user profile cleanup, you can refer to the article below.

SharePoint: The complete guide to user profile cleanup

  • Thanks for the answer! So for me it sounds like that "...RemoveProfile()" delete the user from every Database? It is like a full clean-Up from the system? So its like a manual/scripting way/replacement for the Cleanup-Job? Because the description of the method from Microsoft is not very clear. – LonBoy May 21 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.