-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckAccessRequests.ps1
41 lines (37 loc) · 1.41 KB
/
CheckAccessRequests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
## Send email to admin with links to all pending site access requests ###
Param(
[Parameter(Mandatory=$true)] [string]$rootURL,
[string]$adminEmail,
)
Add-PSSnapin Microsoft.SharePoint.PowerShell
$sites = Get-SPWebApplication $rootURL | Get-SPSite -Limit ALL
$rootWeb = Get-SPWeb $rootURL
$email = $adminEmail
$subject = "Pending Access Requests - $(Get-Date -Format u)"
$body = ""
foreach ( $site in $sites ) {
$webs = $site.AllWebs
foreach ( $web in $webs ) {
$accessRequests = $web.Lists["Access Requests"]
$arURL = $web.Url + "/Access Requests/pendingreq.aspx"
if ($accessRequests.ItemCount -gt 0) {
$pendingRequests = $accessRequests.Items | where {$_['Status'] -eq 0}
if ($pendingRequests.Length -gt 0) {
Write-Output `n$web
$count=0
foreach ($request in $pendingRequests) {
$count++
Write-Output $request.Name
}
$countString = $count.ToString()
$body+="* $web - $countString pending requests - <a href='$arURL'>Access Requests Page</a>. "
}
}
$web.dispose()
}
}
if ($body.Length -gt 0) {
Write-Output "`nSending email to $email"
#Write-Output $body
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($rootWeb,0,0,$email,$subject,$body)
}