Friday, November 30, 2012

Delete SharePoint alerts for orphaned (deleted) users


  1 
  2 $12HiveDir = "${env:CommonProgramFiles}\Microsoft Shared\web server extensions\12\"
  3 cd $12HiveDir
  4 [void][reflection.assembly]::Loadwithpartialname("Microsoft.SharePoint") | out-null
  5 [void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server.Search") | out-null
  6 [void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server") | out-null
  7 
  8 $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local 
  9 $websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]} 
 10 $webapps = @()
 11 
 12 #Change this to match your domain, or even include the OU
 13 $LDAP_Domain = "LDAP://DC=contoso,DC=local"
 14 
 15 #From Check-SharePoint-Orphaned-Users: http://sharepointpsscripts.codeplex.com/releases/view/21699
 16 function Check_User_In_ActiveDirectory([string]$LoginName, [string]$domaincnx)
 17 {
 18     $returnValue = $false
 19     #Filter on User and NTgroups which only exists
 20     $strFilter = "(&(|(objectCategory=user)(objectCategory=group))(samAccountName=$LoginName))"
 21     $objDomain = New-Object System.DirectoryServices.DirectoryEntry($domaincnx)
 22 
 23     $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
 24     $objSearcher.SearchRoot = $objDomain
 25     $objSearcher.PageSize = 1000
 26     $objSearcher.Filter = $strFilter
 27     $objSearcher.SearchScope = "Subtree"
 28 
 29     #$objSearcher.PropertiesToLoad.Add("name")
 30 

No comments:

Post a Comment

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...