-
-
Save balbany/0cdd492cced4479ff13ae00131030d15 to your computer and use it in GitHub Desktop.
SecureItem PowerShell Azure Function (with warmup bypass)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# POST method: $req | |
$requestBody = Get-Content $req -Raw | ConvertFrom-Json | |
Write-Output $requestBody | |
if($requestBody -eq 'WARMUP'){ | |
#Exit - we are all warmed up! | |
Out-File -Encoding Ascii -FilePath $res -inputObject "Warm up signal recieved." | |
} else { | |
#Execute the normal function logic | |
$list = $requestBody.list | |
$id = $requestBody.itemId | |
$readAccess = $requestBody.readAccess | |
$writeAccess = $requestBody.writeAccess | |
#Connect to the SharePoint site | |
Connect-PnPOnline -Url $env:SPUrl -AppId $env:AppId -AppSecret $env:AppSecret | |
#Get the list item | |
$item = Get-PnPListItem -List $list -Id $id | |
#Give the item Author back write permission | |
Set-PnPListItemPermission -List $list -Identity $id -User $item.FieldValues["Author"].Email -AddRole 'Contribute' -ClearExisting | |
#Give read access for those that require it | |
forEach($user in $readAccess) { | |
Set-PnPListItemPermission -List $list -Identity $id -User $user -AddRole 'Read' | |
} | |
#Give write access to those who require it | |
forEach($user in $writeAccess) { | |
Set-PnPListItemPermission -List $list -Identity $id -User $user -AddRole 'Contribute' | |
} | |
#Send the response | |
Out-File -Encoding Ascii -FilePath $res -inputObject "Updated security for: $list - $id" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment