Help with Get-WebApplication

Hi Folks,

I must be missing something simple here, but I can’t understand why I’m having issues with this.

I want to simply get (and match) a VirApp under a specific website.
So, this here command works fine:

Import-Module WebAdministration -ErrorAction Stop
$WebsiteName = "mywebsite.com"
$VirDirName = "LocalVD"
Get-WebApplication -Site $WebsiteName

It will list all VirApps under that site:

Name     Application pool Protocols  Physical Path
----     ---------------- ---------  -------------
LocalVD  mywebsite.com    http       E:\websites\mywebsite\www\LocalVD
access   mywebsites.com   http       E:\SSO\access

So, why is this returning nothing?

$VirApp = (Get-WebApplication -Site $WebsiteName | Where-Object {$_.Name -eq $VirDirName})

The $_.Name should work right? It should match the Name object in the array?

I can even directly get the VirApp name via

Get-WebApplication -Name $VirDirName

and it gives:

Name     Application pool Protocols  Physical Path
----     ---------------- ---------  -------------
LocalVD  mywebsite.com    http       E:\websites\mywebsite\www\LocalVD

But, I need to firstly get a specific website and only a specific VirApp under that site.
So, what is wrong with my statement to match the $_.Name and the $VirDirName variable?

It doesn’t return any value.

What did I miss here?

THANKS!

 

 

Name is a constructed property Get-WebApplication from Path property. You can do $_.Path.Trim(‘/’) -eq $VirDirName

I did a blog post a while back on a similar behaviour. This is done by the formatting configuration for the Module.

Thanks! You’re right, Name is a constructed property, so it really is ‘path’ as what I need to match.

I did it like this in the end:

$PhysicalPath = (Get-WebApplication -Site $Websitename).Collection.physicalpath | Where {$_ -Match $VirDirName}

That gave me the path on the disk (which is what I needed) for the VirApp that matched the variable under the website I needed.