IIS 7.5 FTP Administration Automation Powershell Script (APPCMD)
Posted by Brajesh Panda on July 26, 2012
Here is my FTP user provisioning script for IIS 7.5 FTP server. Later I will publish configuration steps for FTP & FTPS Server.
Most of the below command strings are not from PowerShell. But I used in a PowerShell script because it is easy to pass variables etc. APPCMD.exe is a new command line tool for IIS 7 & above. You will find it in C:\windows\system32\inetsrv. To make it work in your script make sure you configured environmnet variables.
Earlier it used to take 5mins to set up a user account mannually & always I used to forget to do something, resulting frustration. Now it is in seconds & robotic. Isn’t it awesome
# Capture FTP User Details
$UserLogonName=read-host “Enter Logon Name”
$UserPassword=read-host “Enter Password”
$UserFullName=read-host “Enter Full Name”
$UserDescription=read-host “Who use this account?”
# Create Local FTP User, configuring Account Never Expire, User Can’t change password
net user $UserLogonName $UserPassword /add /passwordchg:no /expires:never /active:yes /fullname:$UserFullName /comment:$UserDescription
# Set the FTP user account’s password not to expire using WMI in Powershell
$WMI = gwmi win32_useraccount | where {$_.name -eq $UserLogonName}
$WMI.PasswordExpires = $False
$WMI.put()
# Add FTP User to FTP Users group. This group has permission to connect to this FTP server
net localgroup FTPUsers $UserLogonName /add
# Create FTP Directory for the above FTP user
mkdir C:\WEBRoot\Colliers-International_Com\$UserLogonName
# Create FTP Virtual Directory
appcmd add vdir /app.name:”FTP_Server/” /Path:/$UserLogonName /physicalpath:C:\WEBRoot\$UserLogonName
# Remove FTP Users group from the Virtual Directory. So nobody will able to access this folder
appcmd set config “FTP_Server/$UserLogonName” -section:system.ftpServer/security/authorization /-”[roles='FTPUsers']” /commit:apphost
# Add above FTP user to virtual directory authorization list with read & write permission
appcmd set config “FTP_Server/$UserLogonName” -section:system.ftpServer/security/authorization /+”[accessType='Allow',users='$UserLogonName',permissions='Read, Write']” /commit:apphost
# Automatically open FTP server using windows explorer
explorer.exe ftp://<URL>
Justin said
Waiting for the post on configuration steps for FTP & FTPS Server. Running in to a few errors from this script, and have been able to correct most of them for myself, but I suspect I have a configuration error somewhere in IIS7.5 in relation to this script.
Brajesh Panda said
Thank you Justin. Let me know if I need to correct my script somewhere. Here is the new article about FTPS server installation: http://techontip.wordpress.com/2012/09/07/configure-ftps-server-using-iis/