I need to iterate through all site collections and through all subsites, and print out only the subsites with a certain pattern:
/sites/clientcode/oppcode6digits
Each client site collection has many subsites, but I only need the ones which URL is at the end 6-digit code.
I have this so far but not working:
$SPWebApp = Get-SPWebApplication "https://mylocalurl.com"
foreach ($SPSite in $SPWebApp.Sites) {
if ($SPSite -ne $null -and $SPSite.Url -notmatch "billing" -and $SPSite.Url -notmatch "administrativedocuments" -and $SPSite.Url -notmatch "documentation" -and $SPSite.Url -notmatch "help" -and $SPSite.Url -notmatch "marketing" -and $SPSite.Url -and $SPSite.Url -notmatch "search" -and $SPSite.Url -ne $rootDMS ) {
foreach ($web in $SPSite.AllWebs) {
$regex = ‘\b[0-9]{6}\b’
$patrn = "https://mylocalurl/sites/*/$regex"
Write-Host $web.Url | select-string -Pattern $patrn
}
}
$SPSite.Dispose()
}
"https://mylocalurl/sites/.*/\d{6}`$"https://mylocalurl/sites/abc/123456, so I believe there is a problem not related to regex. Maybe there are 6 digits right aftersites? Then try"https://mylocalurl/sites/(?:[^/]*/)*\d{6}$"