1

I need to delete users from user profile in the view Profile Missing from Import. I tried to run the My Site Cleanup Timer job but they are still there.

How can I do?

9
  • did you run the full profile Sync?
    – Waqas Sarwar MVP
    Nov 10, 2014 at 14:45
  • I wish to delete them without a Full-Sync.
    – Nk SP
    Nov 10, 2014 at 14:46
  • are these accoutns are active in AD or what are their status? and do you know why it fall under missing?
    – Waqas Sarwar MVP
    Nov 10, 2014 at 14:49
  • They were active in AD, now are disabled and so "not active" in SharePoint. I would like to delete them (throw interface or powershell) before the full-Synch (that runs not that often)
    – Nk SP
    Nov 10, 2014 at 14:51
  • #Get the USer Profile Service Information #URL for Central Admin (where the User Profile service lives) $caUrl="central-admin:5000"; $site= new-object Microsoft.SharePoint.SPSite($caUrl); $servercontext=[Microsoft.Office.Server.ServerContext]::GetContext($site); $userprofilemanager=new-object microsoft.office.server.userprofiles.userprofilemanager($servercontext); $p = $userprofilemanager.getUserProfile("domain\username"); $userprofilemanager.RemoveProfile($p)
    – Waqas Sarwar MVP
    Nov 10, 2014 at 14:52

2 Answers 2

0

you can delete it either manually by running the below script

#Get the USer Profile Service Information
 #URL for Central Admin (where the User Profile service lives)
 $caUrl="http://central-admin:5000";
 $site= new-object Microsoft.SharePoint.SPSite($caUrl);
 $servercontext=[Microsoft.Office.Server.ServerContext]::GetContext($site);
 $userprofilemanager=new-object microsoft.office.server.userprofiles.userprofilemanager($servercontext);
$p = $userprofilemanager.getUserProfile("domain\username");

$userprofilemanager.RemoveProfile($p)

OR Use the Powershell command to purge them all.

To view list of all obsolete users, run the below powershell ( give the identity of user profile)

$upa = Get-spserviceapplication <identity>
Set-SPProfileServiceApplication $upa -GetNonImportedObjects $true

To purge them run the below script.

Set-SPProfileServiceApplication $upa -PurgeNonImportedObjects $true

https://technet.microsoft.com/en-us/library/ff681014.aspx

0

In some instances, where the user appears in the "Non Imported User Profiles" screen in the CA but fail to appear in PowerShell using the -GetNonImportedObjects switch, I found the following answer - courtesy of Bugra Postaci's blog (https://blog.bugrapostaci.com/2016/03/30/delete-inactive-users-in-user-profiles)

This generates a SQL query on the User Profile Database (in which the users missing from import can be identified), and generates a command to remove them from the user profile service in SharePoint.

Solution in PowerShell:

#PowerShell Script – Delete Inactive User Profiles – SharePoint 2010/2013
# Credit to Bugra Postaci's blog (https://blog.bugrapostaci.com/2016/03/30/delete-inactive-users-in-user-profiles)

#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 !" 

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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