Stopping and starting an FTP site in IIS 7.5+ from script with ADSI

This article has been moved to its new home here:

There have been many changes over the years with managing the IIS configuration using scripting.  In IIS 6 using WMI which relies on the ADSI model is the recommended approach.  However, with the introduction of IIS 7.5 and now IIS 8 there is a new way of doing things.  This new way is via the Microsoft.ApplicationHost.AdminManager object.

Although some of the IIS manageability features are still available through the metabase compatibility feature, FTP is not one of those features.  As this feature is not supported on IIS 7.5/8 the below script, shown in Figure 1, that works on IIS 6 will not work on IIS 7.5 or IIS 8.

Figure 1, Start an FTP site in IIS 6

To start an FTP site on an IIS 7.5 or IIS 8 instance, use the code shown in Figure 2 instead.

Figure 2, Start all FTP websites on IIS 7.5 or IIS 8

If you wanted to stop only a single website based on the name of the FTP site, create a FindElement function, for example which will search through sitesCollection and return the FTP sites position.  Then you can stop only that FTP site.  Figure 3 is a sample of the method and the parameters.

Figure 3, Sample example of a FindElement method, stop a single FTP site in IIS 7.5 or IIS 8