Hi,
I found this ps1 script off a web site where it will remove deleted AD users from user information list in SharePoint. Trouble is I want the command to read off a csv file under column called "UserName" which will contain AD accounts. Secondly, I want the append a domain prefix in front of user accounts via the script. So within the csv under UserName column, it'll be something like jsmith, jjones. I want the script to pass on domain\jsmith, domain\jjones and procedd withh the deletion.
Please advise.
Script I'm using is:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Define the Array with List of Users
$Users =@('ME\JamieT', 'Corp\EinstinS', 'Global\MarcM')
#Get all Site Collections
$SiteColl = Get-SPWebApplication "https://www.testsite.com" | Get-SPSite -Limit All
#Iterate through all Site Collections
foreach($site in $SiteColl)
{
#Iterate through the users to Remove
foreach($user in $Users)
{
#Check if User Exists in Site
if ($Site.RootWeb.SiteUsers | Where {$_.LoginName -eq $User})
{
$Site.RootWeb.SiteUsers.Remove($User) #You can also use: Remove-SPUser cmdlet
Write-Host "$($user) has been Removed from $($Site.RootWeb.URL)"
}
}
}