2011-12-20 11 views
12

aracılığıyla görüntüleyemiyorum Aşağıdaki ifadeyi çalıştırmaya çalışıyorum.PowerShell cmdlet özelliği gösterir, ancak 'select'

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

Bu

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

sonuçlanır Ama sonuç sonrasında yürüttüğünüzde

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

Yani bu nesne

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 

için özelliklerinde içine baktı boş Yani 'İsim' özelliği yok . Get-webpplication ad özelliğini nasıl gösterebilir, ancak bunu seçemeyiz?

+1

İlgili soru: http://stackoverflow.com/questions/7504027/powershell- WebAdministration-ho w-to-get-website-from-webapplication – BACON

cevap

17

Web Yönetme modülü, ilgili tür için varsayılan biçimi tanımlar. Bu durumda, elde WebApplication Microsoft.IIs.PowerShell.Framework.ConfigurationElement#site#application

bu tip Adı için belirtilen biçim aşağıdaki gibidir (genellikle C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration bulunan) modülün altında dosyanın iisprovider.format.ps1xml bakarsak gördünüz olacağı tiptedir :

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

böylece adı aslında $_.Path.Trim('/') var, bu nedenle isterseniz aynı yapabilirsiniz:

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

WTF .... Bu yüzden powershell'den nefret ediyorum. Tamamen anormal değildir. – Oliver

İlgili konular