PowerShell + WebAdministration - How to get website from webapplication?
This is how you can get the site name:
$siteName = (Get-WebApplication -name 'YourApp').GetParentElement().Attributes['name'].Value
Or even shorter:
$siteName = (Get-WebApplication -name 'YourApp').GetParentElement()['name']
I haven't dug into why, but if you use an asterisk or question mark anywhere in the string it works like a wildcard and returns as such.
I.E.
get-website -name '*myapp' Name ID State Physical Path Bindings ---- -- ----- ------------- -------- myapp 12 Started C:\inetpub\wwwroot http:*:80: amyapp 13 Stopped C:\anetpub\ http:*:81: aamyapp 14 Stopped C:\another\place http:172.198.1.2:80:host.header.com
or
get-website -name '?myapp'Name ID State Physical Path Bindings---- -- ----- ------------- --------amyapp 13 Stopped C:\anetpub http:*:81:
Try this
$app = get-webapplication -name 'MyApp'foreach($a in $app){$a.Attributes[0].Value;}
This will give you all the names of the Web Applications, sometimes you can have more than 1 name for a single Web Applications.
For more information see the link
http://nisanthkv.blog.com/2012/07/06/name-of-web-applications-using-powershell/
Hope it helps..