I have updated the code successfully to include domain\username. It removes user from the group successfully. However, I notice that the below code runs only for first item in the list. It should run for all items in the list. May I know where I am going wrong ?
public override void Execute(Guid targetInstanceId)
{
var currentdate=DateTime.Now.Date;
SPWebApplication webApp = this.Parent as SPWebApplication;
SPList taskList = webApp.Sites[0].AllWebs["dev"].Lists["Limited_Access_To_Security_Groups"];
SPView view = taskList.Views["All Items"]; //custom view name
SPListItemCollection olistitems = taskList.GetItems(view);
foreach (SPListItem item in olistitems)
{
if (Convert.ToDateTime(item["ExpiryDate"]) <= DateTime.Now.Date)
{
string[] loginNameParts = item["UserName"].ToString().Split('\\');
string loginNameWithoutDomain = "i:0#.w|ustdev\\" + loginNameParts[1];
RemoveUser(loginNameWithoutDomain, item["GroupName"].ToString(), "http://dw032/");
item["Status"] = "Expired";
item.Update();
}
else
{
item["Status"] = "Active";
item.Update();
}
}
}