Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module ActiveDirectory
- Clear-Content c:\Scripts\CreateShares\names.txt
- $time = (Get-Date).AddMinutes(-75)
- Get-ADUser -Filter * -Properties * | where { $_.whenCreated -gt $time} | select samaccountname |
- foreach-object
- {
- if(!(Test-Path -path("\\fs02\"+ $_.samaccountname + "$")))
- {
- Add-Content C:\Scripts\CreateShares\names.txt $_.samaccountname
- }
- }
- ForEach($name in Get-Content "C:\Scripts\CreateShares\names.txt")
- {
- $AccountName = "$name"
- $UserRoot = '\\fs02\d$\DFS\Users\'
- $HomeDirectory = $UserRoot+$AccountName
- New-Item -path $HomeDirectory -type directory -force
- $objUser = New-Object System.Security.Principal.NTAccount("DOMAIN\$name")
- $FileSystemAccessRights = [System.Security.AccessControl.FileSystemRights]"FullControl"
- $InheritanceFlags = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit,ObjectInherit"
- $PropagationFlags = [System.Security.AccessControl.PropagationFlags]"None"
- $AccessControl = [System.Security.AccessControl.AccessControlType]"Allow"
- $AccessRule=New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser,'FullControl','ContainerInherit,ObjectInherit','None','Allow')
- $HomeFolderACL = Get-ACL \\fs02\d$\DFS\Users\$AccountName
- $HomeFolderACL.AddAccessRule($AccessRule)
- Set-ACL -path \\fs02\d$\DFS\Users\$AccountName -AclObject $HomeFolderACL
- net share $AccountName$=D:\DFS\Users\$AccountName "/Grant:Everyone,FULL"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement