Python - Assign user to a sub OU - windows

I want to create an user in a Windows Active-Directory to a special OU. I got the right code already that works fine. But I want to create this user to a sub OU e.g.: Company -> User -> Sales.
My code is the following:
def addUser():
pyad.set_defaults(ldap_server="domain.local", username="Administrator", password="mypassword")
ou = pyad.adcontainer.ADContainer.from_dn("ou=Company, ou=User, ou=Sales, dc=domain, dc=local")
new_user = pyad.aduser.ADUser.create("Name", ou, password="UserPassword")
print("sucess")
Is it possible to create the user directly in my OU or do I have to move him afterwards?

This line is where you are setting the OU where you want to create the user:
ou = pyad.adcontainer.ADContainer.from_dn("ou=Company, ou=User, ou=Sales, dc=domain, dc=local")
But I think you formatted it wrong. If the Sales OU is inside the Users OU and the Users OU is inside the Company OU, then it should look like this:
ou = pyad.adcontainer.ADContainer.from_dn("ou=Sales,ou=User,ou=Company,dc=domain,dc=local")
Notice that there should also be no spaces after each comma.

Related

i want auto role in jda, (when member join, add role by id)

i want when user join some discord guild, bot will add role by id to newcomer.
i have already use this code block, but that isn't work!
`
if (((GuildMemberJoinEvent) event).getGuild().getName().equals("something name")){ System.out.println(((GuildMemberJoinEvent) event).getMember().getUser().getName() +((GuildMemberJoinEvent) event).getGuild()); Role r = ((GuildMemberJoinEvent) event).getGuild().getRoleById("1019811149602107402"); ((GuildMemberJoinEvent) event).getMember().getGuild().addRoleToMember(((GuildMemberJoinEvent) event).getMember().getUser(),r); }
`
This is how to grant roles by id:
event.getGuild().addRoleToMember(member, event.getGuild().getRoleById("1034143551568752682")).queue();
Just put this in onGuildMemberJoin and check for guild name like you have here.
Also please make your code readable

Dataset is empty

I have a problem, I'm working on a school project with Visual Basic and I can't manage to fill a dataset with a LIKE query.
I'm using Access in order to manage the database and the query is:
SELECT * FROM VistaProductos WHERE Nombre LIKE "*ta*"
In Access this query is working fine but when I use it on Visual Basic the OleDbDataAdapter fills my DataSet with 0 rows.
Here is the code:
Dim adaptador As New OleDbDataAdapter("SELECT * FROM VistaProductos WHERE " & campo & " LIKE ""*" & valor & "*""", conexion)
adaptador.Fill(dataset, tabla)
Return dataset
campo and valor are variables who have the same data as in the Access example, and I tried by writing them literally too.
The connection to the database is working fine as the other querys work perfectly.
ADO.NET uses the standard % character as wildcard in LIKE expressions.
But your first problem to solve is removing the string concatenations when you build sql queries. You cannot trust your user on this point. If you leave in that way you user can write anything and you risk to pass malicious commands to your database engine. You should always use parameters in these contexts
In your code is present also a field name as a variable part of the query.
This cannot be parameterized, so the only sensible solution is to present your user with a list of field names to choose from
Dim cmdText = "SELECT * FROM VistaProductos WHERE " & campo & " LIKE #valor"
Dim adaptador As New OleDbDataAdapter(cmdText, conexion)
adaptador.SelectCommand.Parameters.Add("#valor", OleDbType.VarWChar).Value = "%" & valor & "%"
adaptador.Fill(dataset, tabla)
Return dataset

Use ldap3 to query all active directory groups a user belongs to

I have no problem to query the domain user from active directory with this query
from ldap3 import ObjectDef, AttrDef, Reader, Entry, Attribute, OperationalAttribute
import ldap3
person = ObjectDef('inetOrgPerson')
s = ldap3.Server('myad.com')
c = ldap3.Connection(s, user = 'myuser', password = 'mypassword')
ldap3.Reader(c, person, '(&(objectCategory=person)(sAMAccountName=myuser))', 'dc=mydomain,dc=com').search()
however, this query returns empty list of groups the user belongs to, how to make it work?
ldap3.Reader(c, person, '(&(objectCategory=group)(member=myuser))', 'dc=mydomain,dc=com').search()
I use ldap3. Thanks in advance.
This answer helped me:
I need the full DN of the user returned from the first query, so this works:
ldap3.Reader(c, person, '(&(member=CN=myuser_in_full_name,OU=xxx,OU=xxxxxx,DC=mydomain,DC=com)(objectClass=group))', 'dc=mydomain,dc=com').search()

Outlook Macro's: Get user initials

I am working on a very, very simple project which sets a followup Flag on a selected message when running a macro.
I have created this so far which works very nicely, but I want to improve it by replacing the manual input of "YA" initials and put the default profile user initials as the initials.
I have found the contactitem object, but I have no idea how to get the initials out of it to put it as a .FlagRequest
Any idea's about this?
This is currently my code: (the GetCurrentItem just returns the selected email)
Public Sub SetCustomFlagNormal()
Dim objMsg As Object
Set objMsg = GetCurrentItem()
With objMsg
.MarkAsTask olMarkThisWeek
.TaskDueDate = Now
.FlagRequest = "YA"
.ReminderSet = True
.ReminderTime = Now + 2
.Save
End With
Set objMsg = Nothing
End Sub
The Outlook object model provides the CurrentUser property for the Namespace and Account classes. The property of the Namespace class returns the display name of the currently logged-on user as a Recipient object.
Sub DisplayCurrentUser()
Dim myNamespace As Outlook.NameSpace
Set myNameSpace = Application.GetNameSpace("MAPI")
MsgBox myNameSpace.CurrentUser
End Sub
The property of the Account class returns a Recipient object that represents the current user identity for the account. See the Name property of the Recipient class.
I have finally found a way.
After getting to multiple website, I was able to determine that Outlook doesn't offer a way to get the user initials and that Word has to be called upon to get the initials
As office uses the same initials throughout all office applications.
I got my response on this website.
http://blogs.technet.com/b/heyscriptingguy/archive/2008/03/18/how-can-i-retrieve-the-user-name-and-user-initials-from-microsoft-powerpoint.aspx
Hope it helps

Accessing admin Account in Joomla

Is there any way I can access the admin account of a website built in Joomla,if I dont have the password for the admin account.I do have all the privileges on the server. Please let me know your suggestions and opinions.
The password is stored in the MySQL database jos_users table password field. (change this for your table prefix if different)
Use a MySQL utility such as phpMyAdmin or MySQL Query Browser to edit this field.
Open the table, find your admin username, and then select that row for editing.
The password must be hashed (MD5), you cannot simply enter text into this field.
Set the password to a known value eg:
- admin = 21232f297a57a5a743894a0e4a801fc3
Source: http://forum.joomla.org/viewtopic.php?t=10985
The admin password you can find it in {DB_PREFIX}_users, the password is hashed (MD5) ...
Well it's a little more complicated than that, the hash is formed like {hashedpassword}:{hashedsalt}, the hashedpassword is formed by md5(password.hashedsalt) ...
so you can make a little script to echo a new password ...
<?php
$psw = 'hashedpassword:hashedsalt'; // you copy the entry from the db here
$newpassword = 'newpassword'; // your new password
list($hashedpassword, $hashedsalt) = explode(":", $psw);
$newpsw = md5($newpassword.$hashedsalt);
$output = $newpsw.":".$hashedsalt;
echo $output; // this is what you put in the db
?>

Resources