I am trying to execute the following statement.
dir IIS:\Sites| foreach{ get-webapplication -site $_.Name} | select -first 1
This results in
Name Application pool Protocols Physical Path
---- ---------------- --------- -------------
i1 DefaultWebSite http C:\inetpub\hosts\DefaultWebSite\i1
But when I execute the following the result is empty
dir IIS:\Sites| foreach{ get-webapplication -site $_.Name} | select -first 1 name
So I looked into the properties for this object
dir IIS:\Sites| foreach{ get-webapplication -site $_.Name} | select -first 1 | get-member | sort
Name | select Name, MemberType | format-table -auto
Name MemberType
---- ----------
applicationPool NoteProperty
Attributes Property
ChildElements Property
ClearLocalData Method
Collection NoteProperty
ConfigurationPathType NoteProperty
Copy Method
Delete Method
ElementTagName Property
enabledProtocols NoteProperty
Equals Method
GetAttribute Method
GetAttributeValue Method
GetChildElement Method
GetCollection Method
GetHashCode Method
GetMetadata Method
GetParentElement Method
GetType Method
Item ParameterizedProperty
ItemXPath NoteProperty
LoadProperties Method
Location NoteProperty
Methods Property
path NoteProperty
PhysicalPath ScriptProperty
PSPath NoteProperty
Schema Property
SetAttributeValue Method
SetMetadata Method
ToPSObject Method
ToString Method
Update Method
UpdateCollection Method
virtualDirectoryDefaults NoteProperty
So no 'Name' property. How is it that the get-webpplication can show the name property, but we cant select it?
The WebAdministration module defines default format for the concerned type. In this case, the WebApplication that you get is of type Microsoft.IIs.PowerShell.Framework.ConfigurationElement#site#application
If you look at the file iisprovider.format.ps1xml
under the module ( usually located at C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration
), you will see that the format specified for the Name of this type is as below:
...
<TableColumnItem>
<ScriptBlock>
$name = $_.Path.Trim('/')
$name
</ScriptBlock>
</TableColumnItem>
...
Thus the name is actually got from $_.Path.Trim('/')
, so you can do the same if you want:
get-webapplication -site "test" | select @{e={$_.Path.Trim('/')};l="Name"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With