How do I get the AD group and add users to it? - active-directory

I haven't done this in so long and I simply want to get the group CoreControls and add a user or another group. How do I write the FindByIdentity? It always return null. The domain is crp.name.local
using (PrincipalContext pc = new PrincipalContext(
ContextType.Domain,
"crp",
username,
password))
{
// group is null and I've tried many examples...
var group = GroupPrincipal.FindByIdentity(pc, "ou=CoreControls");
group.Members.Add(pc, IdentityType.UserPrincipalName, userId);
group.Save();
}

I think the problem is CoreControls is not actually a group, but an OU. So you cannot use GroupPrincipal here. Try this PrincipalContext overload instead:
using (PrincipalContext pc = new PrincipalContext(
ContextType.Domain,
"crp",
"OU=CoreControls,OU=Security,OU=Global Groups,DC=crp,DC=local"
username,
password))
You will have to fiddle with the container parameter to get it just right.

Related

How to filter result to get groups based on users from AZure AD using Microsoft Graph Api

I am getting groups from AZ AD based on users. In one scnaior I need to get all but in other scenario I want to filter and only get groups based on the filter. I used the below code but I am not getting data.
The groups that I need. Technician, Research, ADMIN. I want to just get these groups based on the useridenfiticaiton /email.
Below is the code:
GraphServiceClient graphClient = GetGraphicClient(accessToken);
List<Option> options = new List<Option>();
options.Add(new HeaderOption("ConsistencyLevel", "eventual"));
options.Add(new QueryOption("$filter", $"DisplayName eq 'Technician'"));
// options.Add(new QueryOption("$filter", $"DisplayName eq 'Research'"));
options.Add(new QueryOption("$count", "true"));
var groups = graphClient.Users[uniqueIdentification]
.MemberOf
.Request(options)
.GetAsync().Result;
Note that I need to filter based on all 3 criteria. And be able to store the Group in a List object
Please check if below is the cause as it may be possible.
Try by avoiding result in .GetAsync().Result; which may lead to deadlock condition which may probably lead to no result which looks like your case.
For example: filtered for jobTitle in query options:
List<Option> requestOptions = new List<Option>();
//var requestOptions= new List<Option>();
requestOptions.Add(new QueryOption("$count", "true"));
requestOptions.add(new QueryOption("$filter", " jobTitle eq 'Retail Manager’ "));
requestOptions.add(new QueryOption("$filter", " jobTitle eq 'Marketing Assistant'"));
var request = await graphClient.Users["UPN"].MemberOf
.Request(requestOptions).Header("ConsistencyLevel", "eventual")
// .Filter("(jobTitle eq 'Retail Manager' ) or (jobTitle eq 'Marketing Assistant')") // try this if query options doesn't work
.GetAsync();
In graph explorer tried this :
But not sure later again it gives error as group doesn't have jobTitle as property.
Please check below References:
Graph API .net SDK - Filter Me.MemberOf based on displayName of groups - Stack Overflow
c# - Filtering the transitive group memberships of a user using
Graph SDK - Stack Overflow

How can I fetch all open cases and change the case owner

we have to write a code to Fetch all "Customer - Direct" type accounts and get all its open cases and Change the owners for all these open cases.
You don't need code for this, there's perfectly fine setup -> transfer utility to find & change owners. Or run a report, change it in excel, use import wizard back?
List<Case> cases = [SELECT Id, Account.OwnerId
FROM Case
WHERE IsClosed = false AND Account.Type = 'Customer - Direct'];
for(Case c : cases){
c.OwnerId = c.Account.OwnerId; // I don't know what you want to do,
// you can hardcode specific user's '005...' id here too
}
update cases;

How do I get someones username AND tag? (Discord.js)

So, I'm trying to make a serverInfo command as you can see below
let embed = new Discord.MessageEmbed()
.setColor("GREEN")
.setTitle("Server Information")
.setDescription(`Server Name: **${message.guild.name}** \n ────────────────── \n Member Count: **${message.guild.memberCount}** \n ────────────────── \n Server ID: **${message.guild.id}** \n ──────────────────`)
.setTimestamp()
.setFooter(`Ran by: ${message.author.username.id}`)
message.channel.send(embed)
For my result, I get "undefiened"
anyone know the solution to this? (.setFooter)
message.author.tag for get the user with tag (JohnDoe#0000)
message.author.user for get the user
message.author.user.username for get the Username
message.author.user.id for get the ID
Simple (:
To get the complete tag of a user, you can just use .tag after message.author.
In your code, you're trying to get the username but you put .id after it so this is why you get "undefined".
The ID isn't the numbers with the hashtag, it's the user ID and the tag is the username plus the numbers with the hashtag.
⠀⠀⠀↱ John Doe#3040 ↰
Username⠀⠀⠀⠀ ⠀⠀Numbers
↳⠀⠀⠀⠀⠀⠀⠀⠀Tag⠀⠀⠀⠀⠀⠀⠀ ↲
So, to get the username and tag, just do this:
//say it’s called msg instead of message
var tag = msg.author.tag;
var username = msg.author.id;
//tag would return the user's tag, and as someone else stated in a comment in a previous answer, author returns a user, which itself doesn't have a user property because it is the user object
Also just a quick tip: since it’s server info command, you might want to put some information about the user that’s exclusive to that guild (nickname, roles, permissions), and for that, you can use msg.member which returns a GuildMember, which has a user property, and many more, like member.displayName and member.roles

?members command for my discord bot - discord.js

So I've been trying to create a ?members command which lists all the users with a role.
So far I've got this:
if (message.content.startsWith("?members")) {
let roleName = message.content.split(" ").slice(1).join(" ");
let membersWithRole = message.guild.members.filter(member => {
return member.roles.find("name", roleName);
}).map(member => {
return member.user.username;
})
const embed = new Discord.RichEmbed({
"title": `Members in ${roleName}`,
"description": membersWithRole.join("\n"),
"color": 0xFFFF
});
return message.channel.send(embed);
}
So, it works if you type the exact name of the role, but not when you ping it or type the first word. I've been trying for hours to figure out how to do it, and I figured I should ask for help.
Thanks in advance!
Pings get translated into a code as they come through, there is a lot of information on how to parse them in the official guide After it's parsed into a role id you can just use members.roles.get() because that is what they are indexed by.
As for finding a partial name, for that you are going to have to run a function on your find and use String.includes.
return member.roles.find(role => role.name.includes(roleName));
This will also work for find the whole name of course, so it can replace your existing line.
However, this may result in more than one role. This is also true for searching by the entire role name, however, as there are no restrictions on duplicate named roles. For this you may want to invert you design and search through message.guild.roles first for any matching roles, then search for members with the roles found.

How to get all rolegroups in dotnetnuke

RoleController.GetRoleGroups(portalid); is giving only user created group not Global Roles Group that is created by default.
You can use RoleController.GetRoleGroups() for this :-
var arrGroups = RoleController.GetRoleGroups(portalSettings.PortalId);
foreach (RoleGroupInfo roleGroup in arrGroups)
{
//Your Logic goes here :-
}
You can use RoleController.GetRoles() for this :-
There are two overload of this method :-
IList<RoleInfo> GetRoles(int portalId, Func<RoleInfo, bool> predicate);
IList<RoleInfo> GetRoles(int portalId);
You can see the Source code here :-
This is how you can use the method :-
foreach (var role in TestableRoleController.Instance.GetRoles(portalId))
{
// you can Put your Logic here :-
}
The global role group is really the absence of a role group. So, the "global" group is roles with a group ID of -1.

Resources