Answer the question
In order to leave comments, you need to log in
Script for automatically creating folders with names of domain users, departments, certain accesses?
Good afternoon. For convenience with the management of the domain controller, it was necessary to automate some functions (using scripts) I'm a newbie PS. Please help those who know. Thanks in advance!.
Windows Server 2008 r2.
Such a task. The script should do the following:
1. Automatically create a folder in the exchanger for departments (if there is no corresponding folder)
2. Automatically create a folder in the exchanger (within the corresponding department) after creating a domain user, as Ivanov I.I. (if there is no corresponding folder)
3. That you can configure access to folders. (for example, inside the Ivanov I.I. folder, apart from him and the admin, no one could create or delete anything, only reading)
4. If a person quit, when the domain user was disconnected, the folder was transferred, for example, to the "Junk" folder.
According to the first item, I found the following command
((Get-ADUser username).distinguishedname.Split(','))[1]
but it issues this error.
On the second point, there is such an option. It is also a little unclear how to properly configure access as described.
$newuser = (get-eventlog -log Security -InstanceID 4720 -newest 1).ReplacementStrings[9]
mkdir C:\obmen\$newuser
icacls C:\obmen\$newuser /setowner $newuser /L
cacls C:\obmen\ $newuser /G ($newuser + ":R")
mkdir C:\obmen\$newuser\Private
icacls C:\obmen\$newuser\Private /setowner $newuser /T
cacls C:\obmen\$newuser\Private / G ($newuser + ":R")
Answer the question
In order to leave comments, you need to log in
On the first point - you are looking for a user by substituting something in $newuser
into the Get-ADUser cmdlet
Check out what might be there. Most likely you have something wrong
Get-Help Get-ADUser -Parameter Identity
. Secondly, figure out what exactly this script does, what is missing for you and remake it for yourself. When you figure out what it does, you can understand what is missing.
in general, you seem to be freelancing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question