Answer the question
In order to leave comments, you need to log in
AD + PS - Set all users in AD home folder?
Prompt the script so that all accounts of the Users type register a home folder in AD according to the principle \\server\share\%LOGIN%
Answer the question
In order to leave comments, you need to log in
Import-Module ActiveDirectory #Specify
the network share
$Dir = "\\share\folder\" #Specify the
domain controller
$DC = "DC.comodo.com" #Get
users to the $Users variable to modify
$Users = Get -ADUser -Filter * -SearchBase "OU=Users,DC=comodo,DC=com" -Server $DC
foreach ($User in $Users) {
# Add each required parameter to a variable
$User = $User.sAMAccountName #Create a
directory with username
$Path = $Dir + $User #Apply
all changes to users
Set-ADUser -Identity $User -HomeDrive "Z:" -HomeDirectory "$Path"-Server $DC
}
The simplest, and perhaps clumsy way, is to select all users with shift, then right-click on them, then Properties, then, the Profile tab - check the Home Folder and enter in the field: \\server\share\%username%
$Dir = "\\server\share\"
$Users = Get-ADUser -Filter * -SearchBase "OU=OU,DC=domen,DC=ru"
foreach ($User in $Users) {
$User1 = $User.Name
$Path = New-Item -ItemType Directory -Path $Dir -Name $User1
$User = $User.sAMAccountName
$Path1 = $Dir + "\" + $User1
$Args = New-Object system.security.accesscontrol.filesystemaccessrule($User,"Modify, Synchronize", "ContainerInherit, ObjectInherit", "None", "Allow")
$ACL = Get-Acl $Path
$ACL.SetAccessRule($Args)
Set-Acl -Path $Path -AclObject $ACL
Set-ADUser -Identity $User -HomeDrive "W:" -HomeDirectory "$Path1" -Server server
}
Do backup data, for example through the same Get-ADUser blabla | Export-CSV blabla
1. Form a list of users that need to be changed - for example, through Get-ADUser -SearchBase and drive it into a variable, for example
$users_List = Get-ADUser -SearchBase "OU where users are" -Filter 'enabled -eq $true' -Properties * |Select SamAccountName
2. Pass the list to ForEach and loop through the Set-ADUser command with the necessary keys -HomeDrive and -HomeDirectory
ForEach ($userName in $users_List)
{
Set-ADuser -Identity $userName -HomeDrive " G:" -HomeDirectory blablabla
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question