So this script runs great with no issues when I run it from the users account. However when I turned this into a logon script it doesn’t map the drive or set the permissions… but it does create the folder. I was hoping to get another set of eyes on my script to get opinions on whether or not this was a scripting or administration issue.
It is not failing at (!(test-path “$FolderPath”)), as it does recreate the folder.
$FolderPath = "\\server\users\$env:username" if (!(test-path "$FolderPath")) { $InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::InheritOnly New-Item -ItemType directory -Path $FolderPath $acl = Get-Acl $FolderPath $acl.SetAccessRuleProtection($True, $False) $acl.Access | % { $acl.RemoveAccessRule($_) } $acl.SetOwner([System.Security.Principal.NTAccount] $env:USERNAME) $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$env:username", 'modify', 'Allow') $acl.AddAccessRule($rule) (Get-Item $FolderPath).SetAccessControl($acl) $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("LTPC-DOM\Domain Admins", "FullControl", "ContainerInherit, ObjectInherit", "None", "Allow") $acl.AddAccessRule($rule) (Get-Item $FolderPath).SetAccessControl($acl) (New-Object -ComObject "Wscript.Network").MapNetworkDrive("V:", "$FolderPath") }