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
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) | |
{ | |
#Add SharePoint PowerShell Commands | |
Add-PSSnapin "Microsoft.SharePoint.PowerShell" | |
} | |
#Variables | |
$DatabaseServerName = "SQL2016" | |
$AppPoolName = "Default SharePoint Service App Pool" | |
$AppPoolUserName = "CFCODE2016\SP_Services" |
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
#Once signed into Azure CLI | |
$Token = az account get-access-token --resource-type "aad-graph" | ConvertFrom-Json | |
$AzAccount = az account show | ConvertFrom-Json | |
Connect-AzureAD -AadAccessToken $($Token.accessToken) -AccountId:$($AzAccount.User.Name) -TenantId:$($AZAccount.tenantId) |
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
#Install AzureAD | |
Write-Information -MessageData:"Getting if the AzureAD powershell module is available..." | |
if(-not (Get-Module AzureAD)) { | |
Write-Information -MessageData:"Installing the NuGet Package provider..." | |
Install-PackageProvider -Name:NuGet -Force -Scope:CurrentUser | |
Write-Information -MessageData:"Installing the AzureAD Powershell Module..." | |
Install-Module AzureAD -Scope:CurrentUser -Force | |
} |
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
$bytes = New-Object Byte[] 32 | |
$rand = [System.Security.Cryptography.RandomNumberGenerator]::Create() | |
$rand.GetBytes($bytes) | |
$rand.Dispose() | |
$newClientSecret = [System.Convert]::ToBase64String($bytes) | |
$dtStart = [System.DateTime]::Now | |
$dtEnd = $dtStart.AddYears(2) | |
write-output $newClientSecret |
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
Write-Information "Updating KeyCredential Usage Sign..." | |
New-AzureADServicePrincipalKeyCredential -ObjectId $serviceprincipal.ObjectId -Type:Symmetric -Usage:Sign -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd | Out-Null | |
Write-Information "Updating KeyCredential Usage Verify..." | |
New-AzureADServicePrincipalKeyCredential -ObjectId $serviceprincipal.ObjectId -Type:Symmetric -Usage:Verify -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd | Out-Null | |
Write-Information "Updating PasswordCredential..." | |
New-AzureADServicePrincipalPasswordCredential -ObjectId $serviceprincipal.ObjectId -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd | Out-Null |
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
Write-Information "Remove all KeyCredential started before $(Get-Date $dtStart -Format 'O' )..." | |
$serviceprincipal = Get-AzureADServicePrincipal -All:$true -Filter "DisplayName eq '$SharePointAddInName'" | |
$serviceprincipal.KeyCredentials | ForEach-Object{ | |
$credential = $PSItem | |
if($($credential.StartDate) -lt $dtStart) | |
{ | |
Write-Information -MessageData:"Removing KeyCredential $($credential.KeyId)" | |
Remove-AzureADServicePrincipalKeyCredential -ObjectId:$serviceprincipal.ObjectId -KeyId:$credential.KeyId | |
} | |
} |
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
.\Set-AuditLogs.ps1 -ClientId:<ClientID> | |
-ClientSecret:<AppSecret> | |
-TenantDomain:<Tenant>.onmicrosoft.com | |
-TenantGUID:<Directory ID> | |
-WebHookUrl:https://<Environment>-auditwebhook.azurewebsites.net/API/AuditWebHook | |
-ContentType:Audit.SharePoint |
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
.\Remove-AuditLogs.ps1 -ClientId:<ClientID> | |
-ClientSecret:<AppSecret> | |
-TenantDomain:<Tenant>.onmicrosoft.com | |
-TenantGUID:<Directory ID> | |
-WebHookUrl:https://<Environment>-auditwebhook.azurewebsites.net/API/AuditWebHook | |
-ContentType:Audit.SharePoint |
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
string stringvalue = await req.Content.ReadAsStringAsync(); | |
log.LogInformation($"Req.Content {stringvalue}"); | |
try | |
{ | |
log.LogInformation("Getting validation code"); | |
dynamic data = await req.Content.ReadAsAsync<object>(); | |
string validationToken = data.validationCode.ToString(); | |
log.LogInformation($"Validation Token: {validationToken} received"); | |
HttpResponseMessage response = req.CreateResponse(HttpStatusCode.OK); | |
response.Content = new StringContent(validationToken); |