Create RDS directories (Scheduled Task)

This script is intended to query AD for a list of users (samaccountname). The returned list will be matched against a path to check\create user profile directories for 2008 and up domains. This script only checks for the existence of the directory, and creates it if it does not exist.


$List = Get-ADUser -Filter * -SearchBase "ou=something,dc=jameier,dc=com" | select samaccountname

$Users = $List.samaccountname

#$Users = "username"

foreach ($user in $users) {

$exist = test-path ("\\some\path\to\RDS\" + $user + ".V2")
if ($exist -match $true) {
write-host -foregroundcolor Green ("$user already has a V2 profile directory")
}

else {
new-item -itemtype directory -path ("\\some\path\to\RDS\" + $user + ".V2") # Set path of roaming.V2 profile

$objUser = New-Object System.Security.Principal.NTAccount("corp\$user")
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule($objUser,"FullControl","3","None","Allow")

$objACL = Get-ACL ("\\some\path\to\RDS\" + $user + ".V2") # Set path for ACL
$objACL.AddAccessRule($objACE)

Set-ACL ("\\some\path\to\RDS" + $user + ".V2") $objACL # Set path to modify ACL
}
}