Iis – How to get “Physical Path Credentials Logon Type” for site and application

iispowershell

I have an IIS 8 website setup with an application within.

Using Powershell how can I get the "Physical Path Credentials Logon Type" setting (defaults to ClearText) for both the main site and the application?

What I have tried,

Setup a specific user and non default "Logon Type" for each of the applications.

(get-item IIS:\Sites\MYSITE).physicalPath
(get-item IIS:\Sites\MYSITE).username
(get-item IIS:\Sites\MYSITE).password

get me exactly the values I would expect but there is no "Logon Type" property available.

(get-item IIS:\Sites\MYSITE).virtualDirectoryDefaults

Shows the path,physicalPath,username and password all blank and has "logonMethod" set as the default "ClearText".

(get-item IIS:\Sites\MYSITE).Collection[0].virtualDirectoryDefaults

and

(get-item IIS:\Sites\MYSITE).Collection[1].virtualDirectoryDefaults

both show the same, the path,physicalPath,username and password all blank and the "logonMethod" is set as the default "ClearText".

Reason I want this is to add a check to a script that ensures sites meet a "settings check list", where I have been able to map all the other settings from powershell.

Best Answer

The solution is to stray from the WebAdministration module and into Microsoft.Web.Administration.ServerManager

Add-Type -AssemblyName "Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"
$iis = new-object Microsoft.Web.Administration.ServerManager
($iis.Sites | where { $_.name -eq "MYSITE" }).applications[1] | select -ExpandProperty VirtualDirectories | select LogonMethod

returns

ClearText

The applications[1] indicates the second application, applications[0] is the root application.

The Add-Type version is important to avoid loading the IIS-Express server instance.

FYI because you have to create an instance of the server any changes in IIS manager are not available until you recreate that object.