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
#Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WinRM\Client | |
#Need to set AllowBasic, AllowDigest, AllowUnencryptedTraffic to 1 | |
#Run this to connect to session | |
$UserCredential = Get-Credential | |
$Session = New-PSSession -ConfigurationName "Microsoft.Exchange" -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection | |
Import-PSSession $Session | |
##Be sure to disconnect at the end. | |
#Remove-PSSession $Session |
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
$serviceprincipal = Get-AzureADServicePrincipal -All:$true -Filter "DisplayName eq 'Demo App'" | |
#OR If using APP ID. | |
$serviceprincipalByID = Get-AzureADServicePrincipal -All:$true -Filter "AppId eq 'ab739749-827d-4437-90e5-bf181c5407e0'" |
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 |