Skip to content

Instantly share code, notes, and snippets.

View Yvand's full-sized avatar

Yvan Duhamel Yvand

View GitHub Profile
@Yvand
Yvand / set-proxy.ps1
Created December 21, 2023 13:28
Sets the proxy on a Windows machine
param(
[string]$proxyIp = '10.1.5.4',
[string]$proxyHttpPort = '8080',
[string]$proxyHttpsPort = '8443',
[string]$localDomainFqdn = 'contoso.local'
)
$proxy = 'http={0}:{1};https={0}:{2}' -f $proxyIp, $proxyHttpPort, $proxyHttpsPort
$bypasslist = '*.{0};<local>' -f $localDomainFqdn
# Set WinHTTP proxy
@Yvand
Yvand / new-certificate-export-public-private-keys.ps1
Last active December 4, 2023 13:19
Creates a self signed certificate, exports its public and private keys to the file system, and deletes it from the certificate store
# Variables to edit
$certificateSubjectName = "certificateSubjectName"
$certificatePath = "certificatePath"
$certificatePassword = "certificatePassword"
# Creates the self signed certificate
$certificate = New-SelfSignedCertificate -DnsName $certificateSubjectName -CertStoreLocation "cert:\CurrentUser\My" `
-NotAfter (Get-Date).AddYears(10) -FriendlyName $certificateSubjectName
if ($null -ne $certificate) {
# Exports the certificate's public key
@Yvand
Yvand / FixWindowsUsersSid.cs
Created July 25, 2023 13:21
Inspect specified Windows users on specified web applications, to ensure that their SID has the expected value, and update it if desired, in the scope of the content database only (the change is not farm wide)
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Administration.Claims;
using System;
using System.Collections.Generic;
using System.Linq;
namespace InspectUsersId
{
class UserAccount
{
@Yvand
Yvand / get-aad-token-msal.ps1
Last active February 24, 2025 13:15
Get Azure AD app-only access token for SPO scope using certificate authentication
# loads "Microsoft.Identity.Client.dll" from module "PnP.PowerShell"
$moduleName = "PnP.PowerShell"
$module = Get-InstalledModule -Name $moduleName -ErrorAction SilentlyContinue
if ($null -ne $module) {
$modulePath = $module.InstalledLocation
} else {
$module = Get-Module -ListAvailable -Name $moduleName
if ($null -eq $module) {
Write-Host -ForegroundColor Red "Module '$moduleName' was not found, install it by running 'Install-Module -Name $moduleName'"; return;
}
#!/bin/bash
set -euo pipefail
IFS=$'\n\t ' # Shell uses IFS to determine the field separators. Use the space ' ' to split param_rgNames to an array
# -e: immediately exit if any command has a non-zero exit status
# -u: immediately exit if using a variable not previously declared
# -o: prevents errors in a pipeline from being masked
usage() { echo "Usage: $0 -u <servicePrincipal-id> -s <servicePrincipal-secret> -t <tenant-id> -g '<rgName1 rgName2 rgName3>';" exit 1; }
: '
@Yvand
Yvand / parse-dsc-logs.py
Last active January 31, 2025 16:42
Parse log files generated by the Azure DSC extention to compute the time taken by each resource to apply its configuration
#!/usr/bin/env python
# This script parses log files generated by the Azure DSC extention to compute the time taken by each resource to apply its configuration.
# It prints the result and generates an output.csv file in the path specified
# Logs of the Azure DSC extention are typically located in C:\WindowsAzure\Logs\Plugins\Microsoft.Powershell.DSC\2.83.1.0
# For each resource, it detects the End Set with the time taken, as below:
# VERBOSE: [2025-01-17 10:21:04Z] [VERBOSE] [SP]: LCM: [ End Set ] [[cChocoPackageInstaller]InstallAzureDataStudio] in 9.5250 seconds.
# VERBOSE: [2025-01-17 10:21:48Z] [VERBOSE] [SP]: LCM: [ End Set ] [[ADObjectPermissionEntry]GrantReplicatingDirectoryChanges] in 0.2660 seconds.
@Yvand
Yvand / MigrateWindowsToTrusted.cs
Created December 7, 2016 14:56
Implement IMigrateEntityForWebApplicationCallback to migrate entities from WinClaims to trusted authentication
using Microsoft.IdentityModel.Claims;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Administration.Claims;
using System;
using System.Diagnostics;
namespace ConsoleApplication1
{
/// <summary>
/// Migrate Windows users to be trusted from a specific SPTrustedLoginProvider