0

I can get all of the webs listed out but when I try to add Where-Object, nothing is returned. How do I get this where object working? This is SharePoint 2013.

$WepApp = "http://mywebapp.com/"
$site = Get-SPSite -Limit All $WepApp
$filteredWebs = $site | Get-SPWeb -Limit All | Where-Object {$_.Url -like "*invest*"}
1
  • It seems as if -like does not work right at all. Whether i use the wildcard character or not, nothing is returned.
    – tnk479
    Commented Apr 22, 2022 at 18:25

2 Answers 2

0

I'm a developer so I write my PowerShell in more of a C# style, but something like this should do what you want.

$webapp = "mywebapp.com"

$sites = $webapp | Get-SPSite -Limit All
foreach($site in $sites)
{
    foreach($web in $site.AllWebs)
    {
        if($web.Url -like "*invest*")
        {
            Write-Output "Found $($web.Url)";
        }
    }
}
0

Your script is perfectly working. Don't forget to print the contents of your $filteredWebs variable :)
You can also use AllWebs method:

$webApp = "http://mywebapp.com"
$site = Get-SPSite -Limit All $webApp
$filteredWebs = $site.AllWebs | ? {$_.Url -like "*invest*"}
$filteredWebs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.