Guest User

Untitled

a guest
Feb 10th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. function Write-Log {
  2. [CmdletBinding()]
  3. param(
  4. [Parameter()]
  5. [ValidateNotNullOrEmpty()]
  6. [string]$Message,
  7.  
  8. [Parameter()]
  9. [ValidateNotNullOrEmpty()]
  10. [ValidateSet('Information', 'Warning', 'Error')]
  11. [string]$Severity = 'Information'
  12.  
  13. )
  14.  
  15. [pscustomobject]@{
  16. Time = (Get-Date -f g)
  17. Message = $Message
  18. Severity = $Severity
  19. } | Export-Csv -Path "$env:Temp\LogFile.csv" -Append -NoTypeInformation
  20. }
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. # Install the Windows feature for FTP
  28.  
  29.  
  30. Install-WindowsFeature Web-FTP-Server -IncludeAllSubFeature
  31.  
  32.  
  33. Install-WindowsFeature Web-Server -IncludeAllSubFeature
  34.  
  35.  
  36. <#
  37.  
  38.  
  39. $foo = $false
  40. if ($foo)
  41. {
  42. Write-Log -Message "Package Installed" -Severity Information
  43. }else{
  44.  
  45. Write-Log -Message "Package Not Installed" -Severity Information
  46.  
  47.  
  48. }
  49.  
  50. #>
  51.  
  52.  
  53. # Import the module
  54. Import-Module WebAdministration
  55. Write-Log -Message "Package Installed" -Severity Information
  56.  
  57. # Create the FTP site
  58.  
  59. $FTPSiteName = Read-Host 'Enter site name: ' #Enter Site Name
  60. $FTPPort = 21
  61. $FTPRootDir = 'C:\FTP'
  62.  
  63. New-WebFtpSite -Name $FTPSiteName -Port $FTPPort -PhysicalPath $FTPRootDir
  64.  
  65.  
  66.  
  67. #Create the local Windows group
  68. $FTPGroupName = Read-Host 'Enter group name: ' #Enter Group Name
  69. New-LocalGroup -Name $FTPGroupName
  70.  
  71.  
  72. $Username = Read-Host 'Enter user name: ' #Enter User Name
  73. $Password = Read-Host 'Enter user password: ' -AsSecureString #Enter Password
  74.  
  75. New-LocalUser "$Username" -Password $Password -FullName "First User" -Description "Description of this account."
  76.  
  77.  
  78.  
  79. # Add on FTP user to the group FTP Users
  80.  
  81. Add-LocalGroupMember -Group $FTPGroupName -Member $FTPUserName
  82.  
  83.  
  84.  
  85.  
  86. #Enable basic authentication on the FTP site
  87.  
  88. $FTPSitePath = "IIS:\Sites\$FTPSiteName"
  89. $BasicAuth = 'ftpServer.security.authentication.basicAuthentication.enabled'
  90. Set-ItemProperty -Path $FTPSitePath -Name $BasicAuth -Value $True
  91.  
  92.  
  93.  
  94.  
  95. #Add an authentication read rule for FTP Users
  96.  
  97. ## Allow SSL Connections
  98. Set-ItemProperty "IIS:\Sites\$FTPSitename" -Name ftpServer.security.ssl.controlChannelPolicy -Value 0
  99. Set-ItemProperty "IIS:\Sites\$FTPSiteName" -Name ftpServer.security.ssl.dataChannelPolicy -Value 0
  100.  
  101. ## Enable Basic Authentication
  102. Set-ItemProperty "IIS:\Sites\$FTPSiteName" -Name ftpServer.security.authentication.basicAuthentication.enabled -Value $true
  103.  
  104.  
  105. ##Set User Isolation
  106. Set-ItemProperty "IIS:\Sites\$FTPSiteName" -Name ftpServer.userisolation.mode -Value 3
  107.  
  108. Add-WebConfiguration "/system.ftpServer/security/authorization" -value @{accessType="Allow";roles="";permissions="Read,Write";users="*"} -PSPath IIS:\ -location "$FTPSiteName"
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. # Restart the FTP sit for all change to take effect
  117. Restart-WebItem "IIS:\Sites\$FTPSiteName" -Verbose
Add Comment
Please, Sign In to add comment