2011-12-20 11 views
12

Estoy intentando ejecutar la siguiente declaración.El cmdlet de PowerShell muestra la propiedad, pero no puede mostrarlo mediante 'seleccionar'

dir IIS:\Sites| foreach{ get-webapplication -site $_.Name} | select -first 1 

Esto se traduce en

Name    Application pool Protocols Physical Path 
----    ---------------- --------- ------------- 
i1    DefaultWebSite  http   C:\inetpub\hosts\DefaultWebSite\i1 

Pero cuando ejecuto la siguiente el resultado está vacía

dir IIS:\Sites| foreach{ get-webapplication -site $_.Name} | select -first 1 name 

así que busqué en las propiedades de este objeto

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 

Entonces no hay propiedad 'Nombre' . ¿Cómo es que la aplicación get-web puede mostrar la propiedad del nombre, pero no podemos seleccionarla?

+1

pregunta relacionada: http://stackoverflow.com/questions/7504027/powershell- webadministration-ho w-to-get-web-from-webapplication – BACON

Respuesta

17

El módulo WebAdministration define el formato predeterminado para el tipo en cuestión. En este caso, el WebApplication que se obtiene es de tipo Microsoft.IIs.PowerShell.Framework.ConfigurationElement#site#application

Si nos fijamos en el archivo iisprovider.format.ps1xml debajo del módulo (normalmente se encuentra en C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration), verá que el formato especificado para el nombre de este tipo es la siguiente :

... 
<TableColumnItem> 
    <ScriptBlock> 
     $name = $_.Path.Trim('/') 
     $name 
    </ScriptBlock> 
</TableColumnItem> 
... 

así, el nombre es en realidad ya ha recibido $_.Path.Trim('/'), por lo que se puede hacer lo mismo si lo desea:

get-webapplication -site "test" | select @{e={$_.Path.Trim('/')};l="Name"} 
+0

WTF .... Es por eso que odio PowerShell. Es completamente intuitivo – Oliver

Cuestiones relacionadas