How to add new active directory users to Home Folder with specific Permissions

Once I create the folder ,I want to add active directory users to the home folders and also set permissions. Please advise.

@Varaganti_Srinath

I believe its better you use powershell script and use invoke powershell

Cheers

$homedirectory = “\userdrive” + vbCrLf +
$userid = “*****” + vbCrLf +
“# Creates home directory in Network share and sets user permissions” + vbCrLf +
“If (!(Test-Path $homedirectory)) {” + vbCrLf +
" New-Item -Path $homedirectory -ItemType Directory" + vbCrLf +
“}” + vbCrLf +
$identity = “corp$userid” + vbCrLf +
$fileSystemRights = “FullControl” + vbCrLf +
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule `
-ArgumentList ($identity, $fileSystemRights, “ContainerInherit,ObjectInherit”, “None”, “Allow”) + vbCrLf +
$acl = Get-Acl -Path $homedirectory + vbCrLf +
$acl.SetAccessRule($fileSystemAccessRule) + vbCrLf +
$flag1 = 1 + vbCrLf +
$check = “ok” + vbCrLf +
“Do {” + vbCrLf +
" Try {" + vbCrLf +
" $acl.SetAccessRule($fileSystemAccessRule)" + vbCrLf +
" $check = ‘ok’" + vbCrLf +
" } Catch [System.Management.Automation.RuntimeException] {" + vbCrLf +
" Write-Host $.Exception.Message" + vbCrLf +
" $check = ‘error’" + vbCrLf +
" Start-Sleep -Seconds 2" + vbCrLf +
" $flag1++" + vbCrLf +
" }" + vbCrLf +
" if ($flag1 -ge 10) {" + vbCrLf +
" Write-Host ‘Number of retries exceeded’" + vbCrLf +
" break" + vbCrLf +
" }" + vbCrLf +
“} Until ($check -eq ‘ok’)” + vbCrLf +
“Try {” + vbCrLf +
" Set-Acl -Path $homedirectory -AclObject $acl -ErrorAction Stop" + vbCrLf +
" Write-Host ‘Home directory $homedirectory created and permissions applied successfully’" + vbCrLf +
“} Catch {” + vbCrLf +
" Write-Host 'Error: Permissions could not be applied, failed with error $
, please check manually’" + vbCrLf +
“}”

when trying the above script it throwing the error like below
Method invocation failed because [system.string] does not contain a method named set access rule