获取站点中所有应用程序的名称

时间:2019-06-13 16:19:25

标签: powershell iis

我正在尝试编写一个Powershell脚本,该脚本获取IIS中网站中每个应用程序的名称,以便更改与其关联的应用程序池。我可以访问该网站,但是找不到清晰的方法来获取每个名称?

例如。我想遍历所有这些元素:ApiServices等,然后使用

Set-ItemProperty "IIS:\Sites\RootSite\$loopedValue" -Name 'applicationPool' -Value $NewPool

我正在尝试:

Get-WebApplication -Site 'ABC'

Name             Application pool   Protocols    Physical Path                                                                                                        
----             ----------------   ---------    -------------                                                                                                        
Api              ABC                http         C:\Api
Services         ABC                http         C:\Services
Director         ABC                http         C:\Director
ReportingServer  ABC                http         C:\ReportingServer

但是无法从Name的成员那里获取Get-WebApplication

Get-WebApplication | Get-Member


   TypeName: Microsoft.IIs.PowerShell.Framework.ConfigurationElement#site#application

Name                     MemberType            Definition                                                                                                             
----                     ----------            ----------                                                                                                             
ClearLocalData           Method                void ClearLocalData()                                                                                                  
Copy                     Method                void Copy(Microsoft.IIs.PowerShell.Framework.ConfigurationElement target, bool recurse)                                
Delete                   Method                void Delete()                                                                                                          
Equals                   Method                bool Equals(System.Object obj), bool IEquatable[ConfigurationElement].Equals(Microsoft.IIs.PowerShell.Framework.Conf...
GetAttribute             Method                Microsoft.IIs.PowerShell.Framework.ConfigurationAttribute GetAttribute(string attributeName)                           
GetAttributeValue        Method                System.Object GetAttributeValue(string attributeName)                                                                  
GetChildElement          Method                Microsoft.IIs.PowerShell.Framework.ConfigurationElement GetChildElement(string elementName), Microsoft.IIs.PowerShel...
GetCollection            Method                Microsoft.IIs.PowerShell.Framework.ConfigurationElementCollection GetCollection(string collectionName), Microsoft.II...
GetHashCode              Method                int GetHashCode()                                                                                                      
GetMetadata              Method                System.Object GetMetadata(string metadataType)                                                                         
GetParentElement         Method                Microsoft.IIs.PowerShell.Framework.ConfigurationElement GetParentElement()                                             
GetType                  Method                type GetType()                                                                                                         
LoadProperties           Method                void LoadProperties(System.Collections.Generic.Dictionary[string,System.Object] propCollection)                        
SetAttributeValue        Method                void SetAttributeValue(string attributeName, System.Object value)                                                      
SetMetadata              Method                void SetMetadata(string metadataType, System.Object value)                                                             
ToPSObject               Method                psobject ToPSObject(Microsoft.IIs.PowerShell.Framework.ConfigurationElement parent)                                    
ToString                 Method                string ToString()                                                                                                      
Update                   Method                void Update(Microsoft.IIs.PowerShell.Framework.ConfigurationElement source), bool Update(psobject data)                
UpdateCollection         Method                bool UpdateCollection(psobject[] arr)                                                                                  
applicationPool          NoteProperty          string applicationPool=ABC                                                                                           
Collection               NoteProperty          psobject[] Collection=System.Management.Automation.PSObject[]                                                          
ConfigurationPathType    NoteProperty          ConfigurationPathNodeType ConfigurationPathType=Location                                                               
enabledProtocols         NoteProperty          string enabledProtocols=http                                                                                           
ItemXPath                NoteProperty          string ItemXPath=/system.applicationHost/sites/site[@name='ABC' and @id='1']/application[@path='/API']            
Location                 NoteProperty          string Location=                                                                                                       
path                     NoteProperty          string path=/ApiDoc                                                                                                    
preloadEnabled           NoteProperty          bool preloadEnabled=False                                                                                              
PSPath                   NoteProperty          string PSPath=MACHINE/WEBROOT/APPHOST                                                                                  
serviceAutoStartEnabled  NoteProperty          bool serviceAutoStartEnabled=False                                                                                     
serviceAutoStartProvider NoteProperty          string serviceAutoStartProvider=                                                                                       
virtualDirectoryDefaults NoteProperty          Microsoft.IIs.PowerShell.Framework.ConfigurationElement#application#virtualDirectoryDefaults virtualDirectoryDefault...
Item                     ParameterizedProperty System.Object Item(string attributeName) {get;set;}                                                                    
Attributes               Property              Microsoft.IIs.PowerShell.Framework.ConfigurationAttributeCollection Attributes {get;}                                  
ChildElements            Property              Microsoft.IIs.PowerShell.Framework.ConfigurationChildElementCollection ChildElements {get;}                            
ElementTagName           Property              string ElementTagName {get;}                                                                                           
Methods                  Property              Microsoft.IIs.PowerShell.Framework.ConfigurationMethodCollection Methods {get;}                                        
Schema                   Property              Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema Schema {get;}                                            
PhysicalPath             ScriptProperty        System.Object PhysicalPath {get=$pquery = $this.ItemXPath + "/virtualDirectory[@path='/']/@physicalPath"...

我真的不想从stringpath解析一个PhysicalPath值来做到这一点。还有另一种方法吗?

1 个答案:

答案 0 :(得分:1)

以下内容将提供所有站点的应用程序名称:

(Get-ChildItem -Path 'IIS:\Sites' -Recurse | Where-Object {$_.NodeType -eq 'application'}).Name

以下内容将返回默认网站的应用程序名称:

(Get-ChildItem -Path 'IIS:\Sites\Default Web Site' | Where-Object {$_.NodeType -eq 'application'}).Name