Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. Import-Module ActiveDirectory
  2. Clear-Content c:\Scripts\CreateShares\names.txt
  3. $time = (Get-Date).AddMinutes(-75)
  4.  
  5. Get-ADUser -Filter * -Properties * | where { $_.whenCreated -gt $time} | select samaccountname |
  6. foreach-object
  7. {
  8. if(!(Test-Path -path("\\fs02\"+ $_.samaccountname + "$")))
  9. {
  10. Add-Content C:\Scripts\CreateShares\names.txt $_.samaccountname
  11. }
  12. }
  13.  
  14. ForEach($name in Get-Content "C:\Scripts\CreateShares\names.txt")
  15. {
  16. $AccountName = "$name"
  17. $UserRoot = '\\fs02\d$\DFS\Users\'
  18. $HomeDirectory = $UserRoot+$AccountName
  19.  
  20. New-Item -path $HomeDirectory -type directory -force
  21.  
  22. $objUser = New-Object System.Security.Principal.NTAccount("DOMAIN\$name")
  23. $FileSystemAccessRights = [System.Security.AccessControl.FileSystemRights]"FullControl"
  24. $InheritanceFlags = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit,ObjectInherit"
  25. $PropagationFlags = [System.Security.AccessControl.PropagationFlags]"None"
  26. $AccessControl = [System.Security.AccessControl.AccessControlType]"Allow"
  27.  
  28. $AccessRule=New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser,'FullControl','ContainerInherit,ObjectInherit','None','Allow')
  29.  
  30. $HomeFolderACL = Get-ACL \\fs02\d$\DFS\Users\$AccountName
  31. $HomeFolderACL.AddAccessRule($AccessRule)
  32.  
  33. Set-ACL -path \\fs02\d$\DFS\Users\$AccountName -AclObject $HomeFolderACL
  34.  
  35. net share $AccountName$=D:\DFS\Users\$AccountName "/Grant:Everyone,FULL"
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement