EXECUTE PROCEDURE setLanguageOfGroupMembers ();
//C:/mstrblog/ADGroups.txt
//mstr_project1_group1;Lang_EN_Finance
//mstr_project1_group2;Lang_FR_Finance


//Read AD pattern from txt file
String sPropFileLine = null;
BufferedReader oBufReader = null;
String[] GroupArr = null;
try {
oBufReader = new BufferedReader(new FileReader("C:/mstrblog/ADGroups.txt"));
while ((sPropFileLine = oBufReader.readLine()) != null) {
GroupArr = sPropFileLine.split(";");
//Read AD users by group name
StringBuffer sADAllUsers = new StringBuffer();
sADAllUsers.append("cmd /c dsget group \"CN="+GroupArr[0]+",OU=Resource Access,OU=Groups,OU=Enterprise,DC=mstrblog,DC=co,DC=uk\" -members | dsget user -dn"); 
Process procReadADUsers=Runtime.getRuntime().exec(sADAllUsers.toString());
BufferedReader brInputReadADUsers = new BufferedReader(new InputStreamReader(procReadADUsers.getInputStream()));
BufferedReader brErrorReadADUsers = new BufferedReader(new InputStreamReader(procReadADUsers.getErrorStream()));
String sReadADUserErrors = null; 
String sReadADUser = brInputReadADUsers.readLine();
String unprocessedUserDN = brInputReadADUsers.readLine();
while (unprocessedUserDN!= null) { 
if((! unprocessedUserDN.equals("dsget succeeded"))) {
sReadADUser =(unprocessedUserDN.substring((int)unprocessedUserDN.indexOf('=')+1,(int)unprocessedUserDN.indexOf(','))).trim().toLowerCase(); 
ResultSet oLanguage = executeCapture("LIST ALL LANGUAGES AT USER LEVEL FOR USER \""+sReadADUser+"\";");
oLanguage.moveFirst();
while(!oLanguage.isEof()) {
String oLang = (String) oLanguage.getResultCell(DisplayPropertyEnum.LANGUAGE).getValue();
String oLangType= (String) oLanguage.getResultCell(DisplayPropertyEnum.LANGUAGE_TYPE).getValue();
if(oLangType.equals("MicroStrategy Metadata")) { 
if(!oLang.equals(GroupArr[1])) { 
execute("ALTER LANGUAGE FOR METADATA AT USER LEVEL FOR USER \""+sReadADUser+"\" USE \""+GroupArr[1]+"\";");
printOut("Metadata language settings changed for user "+sReadADUser+" to "+GroupArr[1]);
}
}
if(oLangType.equals("Data")) { 
if(!oLang.equals(GroupArr[1])) { 
execute("ALTER LANGUAGE FOR DATA AT USER LEVEL FOR USER \""+sReadADUser+"\" USE \""+GroupArr[1]+"\";");
printOut("Data language settings changed for user "+sReadADUser+" to "+GroupArr[1]);
}
}
oLanguage.moveNext();
} 
} 
unprocessedUserDN = brInputReadADUsers.readLine();
}
while ((sReadADUserErrors = brErrorReadADUsers.readLine()) != null) {
printOut("Error reading members of AD group "+GroupArr[0]+": "+sReadADUserErrors); 
}
int exitValue = procReadADUsers.waitFor(); 
printOut("Exit Status: "+exitValue);
sADAllUsers.delete(0,sADAllUsers.length()); 
}
}
catch (Exception e) {
printErr("Error reading properties file: " + e.getLocalizedMessage());
}

Leave a Reply

Your email address will not be published. Required fields are marked *