Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Import-Module WebAdministration
  2. Write-Host -foregroundcolor Yellow 'Admin Privileges Required!'
  3. #create local user
  4. $accountName = 'someUser'
  5. $password = 'somePassword'
  6.  
  7. $day = get-date -format "MM.dd.yyyy"
  8. $description = "$day account activated"
  9. $computer = [ADSI]"WinNT://$env:computername,computer"
  10. $user = $computer.Create("user", $accountName)
  11. $user.SetPassword($password)
  12. $user.SetInfo()
  13. $user.Description = $description
  14. $user.SetInfo()
  15. $user.userflags = 65536 -bor 64 #user cant change / never expire
  16. $user.SetInfo()
  17. $ServerName = 'someComputerName'
  18. $group = [ADSI]"WinNT://$ServerName/FTP USER"
  19. $group.add("WinNT://$ServerName/$accountName") ;
  20. #END create local user
  21.  #create users web directory publish folder
  22. New-Item -path C:\inetpub\ftproot\Localuser `
  23. -name $accountName -type directory
  24. Start-Sleep -Seconds 3
  25. New-Item "IIS:\Sites\Default Web Site\$accountName" `
  26. -type VirtualDirectory -physicalPath C:\inetpub\ftproot\Localuser\$accountName
  27.  
  28.  #this function sets access rules for user
  29. Function Acl-Rule
  30. {
  31. #target folder that needs security rules added
  32. $target = "C:\inetpub\ftproot\Localuser\" + $accountName
  33. $mydir = get-acl $target
  34. #allow the proper account Modify control from $account
  35. $rule = new-object system.security.accesscontrol.filesystemaccessrule`
  36.  ($accountName,"Modify", "containerinherit,objectinherit","none","allow")
  37. #Add the access rule to be applied later
  38. $mydir.addaccessrule($rule)
  39. #}
  40. #apply all access rules to target directory
  41. set-acl $target $mydir
  42.  }#end function
  43.  
  44.  Acl-Rule
  45.  
  46. #END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement