TechOnTip Weblog

Run book for Technocrats

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 {$ -eq $UserLogonName}

$WMI.PasswordExpires = $False


# 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 /”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>


2 Responses to “IIS 7.5 FTP Administration Automation Powershell Script (APPCMD)”

  1. 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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: