PowerShell + WebAdministration - 如何从webapplication获取网站? [英] PowerShell + WebAdministration - How to get website from webapplication?

查看:439
本文介绍了PowerShell + WebAdministration - 如何从webapplication获取网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写PowerShell脚本以在IIS 7.5中执行某些管理功能。

I'm writing a PowerShell script to perform certain administrative functions in IIS 7.5.

import-module WebAdministration

在某些情况下,我知道我想要使用的Web应用程序的名称,但不知道它所在的网站。获取应用程序很简单:

In some cases I know the name of the web application I want to work with but not the web site it is under. Getting the application is easy:

$app = get-webapplication -name 'MyApp'

但我无法弄清楚如何在给定应用程序的情况下获取网站的名称。它似乎不是webapplication对象的属性。我想出的最好的尝试是通过测试路径获得它:

But I cannot figure out how to get the name of the web site given the app. It doesn't seem to be a property off the webapplication object. Best I could come up with was trying to get it via test-path:

get-website | where {test-path "iis:\sites\$_.name\MyApp"}

由于某些原因,空的。有关如何解决此问题的任何想法?在此先感谢。

For some reason that comes up empty. Any thoughts on how to go about this? Thanks in advance.

推荐答案

以下是获取网站名称的方法:

This is how you can get the site name:

$siteName = (Get-WebApplication -name 'YourApp').GetParentElement().Attributes['name'].Value

甚至更短:

$siteName = (Get-WebApplication -name 'YourApp').GetParentElement()['name']

这篇关于PowerShell + WebAdministration - 如何从webapplication获取网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆