grovy script for list of active and inactive users

Murthy Dusanapudi June 10, 2021

Hi all can anyone please help me with the script for getting the list of users in jira  Name, Email Address, and active and in active users list and created , last updated date in a single script? is that possible to get all these details in a single script? please help me in this thank you in advance 

1 answer

0 votes
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 10, 2021

Hi @Murthy Dusanapudi 

Run below Script in Script console. 

in Status column :- False means inactive user and true means active user. 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager
import java.text.SimpleDateFormat;
import java.util.Date;
import com.atlassian.jira.user.util.UserUtil
UserUtil userUtil = ComponentAccessor.getUserUtil()
def loginManager = ComponentAccessor.getComponentOfType(LoginManager.class)
def users=ComponentAccessor.getUserUtil().getUsers()
StringBuilder builder=new StringBuilder()
builder.append("<table border = 1><tr><td><b>User Name</b></td><td><b>Full Name</b></td><td><b>eMail Address</b></td><td><b>Last Login</b></td><td><b>Status</b></td><td><b>Group</b></td></tr>")
users.each{
Long lastLoginTime = loginManager.getLoginInfo(it.username).getLastLoginTime()
String activeStatus=it.active
if(activeStatus=="false")
builder.append("<tr><td>"+it.username+"</td><td>"+it.displayName+"</td><td>"+it.emailAddress+"</td><td>Inactive User</td><td>"+it.active+"</td></tr>")
else if(lastLoginTime==null)
builder.append("<tr><td>"+it.username+"</td><td>"+it.displayName+"</td><td>"+it.emailAddress+"</td><td>Logon not found</td><td>"+it.active+"</td></tr>")
else if(userUtil.getGroupsForUser(it.getName()).size() == 0)
builder.append("<tr><td>"+it.username+"</td><td>"+it.displayName+"</td><td>"+it.emailAddress+"</td><td>No Group added</td><td>"+it.active+"</td></tr>")
else{
Date date=new Date(lastLoginTime);
SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yy hh:mm");
String dateText = df2.format(date);
builder.append("<tr><td>"+it.username+"</td><td>"+it.displayName+"</td><td>"+it.emailAddress+"</td><td>"+dateText+"</td><td>"+it.active+"</td></tr>")
}

}
builder.append("</table>")
return builder
Murthy Dusanapudi June 14, 2021

Hi @Vikrant Yadav its working now tnq soo much for the script ...and how can i get these details in confluence?

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 14, 2021

Cool! Glad to hear it works for you. 

For Confluence i am not sure, we dont have Script Runner installed in Confluence. 

Start new Conversation in Atlassian Community for Confluence.  

Thanks,

Om Joshi May 5, 2022

the script is not returning last logon for the active/true users also not returning groups the user belongs to.

Would be able to work on your query? as it is really good one... also want to find out how to automate this to run every 30days or 90days... as a scheduled job. that would be very much helpful.

govardhan reddy June 30, 2022

@Vikrant Yadav same question but we need extract it into excel.
Actually while run this script in console we are getting below error.

Error

This resource requires WebSudo.

 

Please resolve my issue, Thank in advance

govardhan reddy June 30, 2022

This is the latest error after running above script

 

groovy.lang.MissingPropertyException: No such property: username for class: com.atlassian.jira.crowd.embedded.ofbiz.OfBizUser at Script73$_run_closure1.doCall(Script73.groovy:12) at Script73.run(Script73.groovy:11)

 

Please provide me the solution

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 30, 2022

Hi @govardhan reddy  try this script :-   https://gist.github.com/vikrantyadav11/b5697244994b3ce46e20831ed0ef43f4

run script in script console. You will get user data in email body and user details in csv file . It include last login, username , full name , email address, status false for inactive user. 

govardhan reddy July 1, 2022

Hi @Vikrant Yadav the above scipt  getting these errors, the jira version is old 6.4.13, please suggest the script for these errors and let me know how to rectify.

Actually doesnt know the groovy script.

Thanks in advance..

 

2022-07-01 04:06:33,843 WARN [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingPropertyException: No such property: username for class: com.atlassian.jira.crowd.embedded.ofbiz.OfBizUser at Script3$_run_closure1$_closure4$_closure5$_closure6$_closure8.doCall(Script3.groovy:59) at Script3$_run_closure1$_closure4$_closure5$_closure6.doCall(Script3.groovy:58) at Script3$_run_closure1$_closure4$_closure5$_closure6.doCall(Script3.groovy) at Script3$_run_closure1$_closure4$_closure5.doCall(Script3.groovy:50) at Script3$_run_closure1$_closure4$_closure5.doCall(Script3.groovy) at Script3$_run_closure1$_closure4.doCall(Script3.groovy:49) at Script3$_run_closure1$_closure4.doCall(Script3.groovy) at Script3$_run_closure1.doCall(Script3.groovy:48) at Script3$_run_closure1.doCall(Script3.groovy) at Script3.run(Script3.groovy:27)

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 1, 2022

@govardhan reddy  I have tested on my machine it’s working fine. Kindly try to update scriptrunner version 

Suggest an answer

Log in or Sign up to answer