Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Write-Log {
- [CmdletBinding()]
- param(
- [Parameter()]
- [ValidateNotNullOrEmpty()]
- [string]$Message,
- [Parameter()]
- [ValidateNotNullOrEmpty()]
- [ValidateSet('Information', 'Warning', 'Error')]
- [string]$Severity = 'Information'
- )
- [pscustomobject]@{
- Time = (Get-Date -f g)
- Message = $Message
- Severity = $Severity
- } | Export-Csv -Path "$env:Temp\LogFile.csv" -Append -NoTypeInformation
- }
- # Install the Windows feature for FTP
- Install-WindowsFeature Web-FTP-Server -IncludeAllSubFeature
- Install-WindowsFeature Web-Server -IncludeAllSubFeature
- <#
- $foo = $false
- if ($foo)
- {
- Write-Log -Message "Package Installed" -Severity Information
- }else{
- Write-Log -Message "Package Not Installed" -Severity Information
- }
- #>
- # Import the module
- Import-Module WebAdministration
- Write-Log -Message "Package Installed" -Severity Information
- # Create the FTP site
- $FTPSiteName = Read-Host 'Enter site name: ' #Enter Site Name
- $FTPPort = 21
- $FTPRootDir = 'C:\FTP'
- New-WebFtpSite -Name $FTPSiteName -Port $FTPPort -PhysicalPath $FTPRootDir
- #Create the local Windows group
- $FTPGroupName = Read-Host 'Enter group name: ' #Enter Group Name
- New-LocalGroup -Name $FTPGroupName
- $Username = Read-Host 'Enter user name: ' #Enter User Name
- $Password = Read-Host 'Enter user password: ' -AsSecureString #Enter Password
- New-LocalUser "$Username" -Password $Password -FullName "First User" -Description "Description of this account."
- # Add on FTP user to the group FTP Users
- Add-LocalGroupMember -Group $FTPGroupName -Member $FTPUserName
- #Enable basic authentication on the FTP site
- $FTPSitePath = "IIS:\Sites\$FTPSiteName"
- $BasicAuth = 'ftpServer.security.authentication.basicAuthentication.enabled'
- Set-ItemProperty -Path $FTPSitePath -Name $BasicAuth -Value $True
- #Add an authentication read rule for FTP Users
- ## Allow SSL Connections
- Set-ItemProperty "IIS:\Sites\$FTPSitename" -Name ftpServer.security.ssl.controlChannelPolicy -Value 0
- Set-ItemProperty "IIS:\Sites\$FTPSiteName" -Name ftpServer.security.ssl.dataChannelPolicy -Value 0
- ## Enable Basic Authentication
- Set-ItemProperty "IIS:\Sites\$FTPSiteName" -Name ftpServer.security.authentication.basicAuthentication.enabled -Value $true
- ##Set User Isolation
- Set-ItemProperty "IIS:\Sites\$FTPSiteName" -Name ftpServer.userisolation.mode -Value 3
- Add-WebConfiguration "/system.ftpServer/security/authorization" -value @{accessType="Allow";roles="";permissions="Read,Write";users="*"} -PSPath IIS:\ -location "$FTPSiteName"
- # Restart the FTP sit for all change to take effect
- Restart-WebItem "IIS:\Sites\$FTPSiteName" -Verbose
Add Comment
Please, Sign In to add comment