James,
I was able to solicit assistance from user "cduff" on the SpiceWorks forums. Here is the modified code that is operating without errors:
#
# Get the user account SAMAccount names from specific OU and dump into text file
#
# Get-ADUser -filter * -SearchBase "ou=KDBDOM Users,dc=ad,dc=kdbdom,dc=us" | Select sAMAccountName > c:\Test\kdbdom.txt
#
Get-ADUser -filter * -SearchBase "ou=KDBDOM Users,dc=ad,dc=kdbdom,dc=us" | Select-Object -ExpandProperty sAMAccountName > c:\Test\kdbdom.txt
#
# Pull user SAMAccount names from text file and create associated folder.
#
$users = Get-Content "C:\Test\kdbdom.txt"
#
# Create folders for each user in text file based upon sAMAccountName flag on User Object
#
ForEach($user in $users)
{
$newPath = Join-Path "c:\Test" -childpath $user
New-Item $newPath -type directory -Force
# Assign Full Control permissions to new folders created by sAMAccountName flag on User Object
$acl = (Get-Item $newpath).GetAccessControl('Access')
$permission = "KDBDOM\$user","FullControl",@("ContainerInherit","ObjectInherit"),"None","Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl $newpath
}
The fixes for my initial code were:
And
and lastly: