Quantcast
Channel: Software Communities : Popular Discussions - ActiveRoles
Viewing all articles
Browse latest Browse all 1277

writting a script that will remove disabled profiles from SharePoint 2010

$
0
0

and I have run into a problem.I need to locate users that are just in an OU=NetIQRecycleBin, but I can't figure out how to do it. I am using ActiveRoles, and this is what I have so far:

#Find out how many accounts we should delete ( I’ll make this interogate UPS at some point in future
#for now this fudge will do
Param ([int]$limit)

if (!$limit)
{
$limit = 999999999
}

$count = 1

write-host “————- Started ————-”
$output = Get-Date
$output = “Started at ” + $output.ToString()
$output | Out-File -FilePath c:\output.txt -append
#Add SharePoint PowerShell SnapIn if not already added
if ((Get-PSSnapin “Microsoft.SharePoint.PowerShell” -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin “Microsoft.SharePoint.PowerShell”
}
#Add Quest AD PowerShell SnapIn if not already added
if ((Get-PSSnapin “Quest.ActiveRoles.ADManagement” -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin “Quest.ActiveRoles.ADManagement”
}
#Set my site host location.

$site=(Get-SPSite https://mysitestg)
$ServiceContext = [Microsoft.Office.Server.ServerContext]::GetContext($site)


#Get UserProfileManager and get all profiles
$ProfileManager = New-Object "Microsoft.Office.Server.UserProfiles.UserProfileManager" -ArgumentList ($ServiceContext)
#= new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)
$AllProfiles = $ProfileManager.GetEnumerator()

#iterate around the profiles
foreach($profile in $AllProfiles)
{
#get the associated AD account
$ADUser = $PROFILE.MultiloginAccounts | Get-QADUser

#check if the account is diasabled in AD
if ($ADUser.AccountIsDisabled)
{
#delete the profile
$ProfileManager.RemoveUserProfile($ADUser.NTAccountName)
$output = $count.ToString() + “: ” + $ADUser.NTAccountName
$output | Out-File -FilePath c:\output.txt -append
write-host $output

$count++
if ($count -gt $limit)
{
break
}
}
}

write-host “————- Finished ————-”
write-host ($count -1) accounts removed
$output = Get-Date
$output =  $output.ToString()
$output | Out-File -FilePath c:\output.txt -append

$site.Dispose()

 

Which works, but it also deletes users from other OU's as well, like ,OU=TerminatedUsers.

 

Anyway, thanks in advance for any help anyone can give me.


Viewing all articles
Browse latest Browse all 1277

Trending Articles