Skip to content

Instantly share code, notes, and snippets.

@BrianTJackett
BrianTJackett / PS-WinGet_Apps_To_Install.ps1
Last active May 30, 2021 18:25
Script for re-installing applications via winget to new machine
winget install Microsoft.dotnet
winget install Microsoft.PowerShell
winget install Microsoft.WindowsTerminal
winget install Postman.Postman
winget install Notepad++.Notepad++
winget install Telerik.Fiddler
winget install Microsoft.VisualStudioCode
winget install Microsoft.VisualStudio.Enterprise
winget install Microsoft.Powertoys
winget install microsoft.mousewithoutborder
@BrianTJackett
BrianTJackett / EXO-New_SCCeDiscoveryCaseAndHold.ps1
Last active September 13, 2020 14:28
Create an Office 365 Security and Compliance Center eDiscovery case, hold, and content search. Warning: uses basic authentication which will be deprecated in Oct 2020.
Set-StrictMode -Version "Latest"
# eDiscovery case creation
$caseName = 'Smith v. Johnson';
$UPN = 'user1@contoso.onmicrosoft.com', 'user2@contoso.onmicrosoft.com'
$description = "$caseName"
$policyName = "$caseName - Hold Policy"
$ruleName = "$caseName - Hold Rule"
$searchName = "$caseName - Search Name"
$rootFolderNameQuery = "Legal Hold"
@BrianTJackett
BrianTJackett / PS-O365_admin_creds.ps1
Created November 15, 2019 16:14
This snippet will store credentials for 2 different accounts encrypted to disk. They will then be loaded into PSCredentials as global variables. Place this in your profile for automatic loading.
New-PSDrive -Name Scripts -PSProvider FileSystem -Root <folderLocationOfScriptsGoesHere>
#read-host -AsSecureString -Prompt "Enter O365 password 1" | ConvertFrom-SecureString | set-content scripts:\O365AdminPassword1.txt
#read-host -AsSecureString -Prompt "Enter O365 password 2" | ConvertFrom-SecureString | set-content scripts:\O365AdminPassword2.txt
function Import-O365AdminCredential
{
$smtpAddress1 = "admin@m365x974797.onmicrosoft.com"
$CredsFile1 = "Scripts:\O365AdminPassword1.txt"
@BrianTJackett
BrianTJackett / WT-profiles.json
Last active May 17, 2021 12:59
Windows Terminal settings.json file with included shells (profiles) for PowerShell v7, Zsh, and more.
// This file was initially generated by Windows Terminal 1.0.1811.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@BrianTJackett
BrianTJackett / PS-Get_PowerApps_App_Connections.ps1
Created March 14, 2019 00:16
Iterate through all environments and get all PowerApps apps and the connections they use.
Add-PowerAppsAccount
$environments = Get-PowerAppEnvironment
foreach($environ in $environments.EnvironmentName)
{
$apps = Get-AdminPowerApp -EnvironmentName $environ
$apps | Add-Member -MemberType ScriptProperty -Name Connections -Value {$this.internal.properties.connectionReferences.PSObject.Properties.Value.DisplayName} -Force
$apps | Select-Object AppName, DisplayName, Connections
}
var graphResult = graphClient.Users.Request().GetAsync().Result;
Console.WriteLine(graphResult[0].DisplayName);
@BrianTJackett
BrianTJackett / CS-Graph_Class_MsalAuthenticationProvider.cs
Last active October 7, 2019 16:35
Microsoft Graph create class to handle authentication with Azure AD and use access token on subsequent requests.
public class MsalAuthenticationProvider : IAuthenticationProvider
{
private IConfidentialClientApplication _clientApplication;
private string[] _scopes;
public MsalAuthenticationProvider(IConfidentialClientApplication clientApplication, string[] scopes) {
_clientApplication = clientApplication;
_scopes = scopes;
}
@BrianTJackett
BrianTJackett / CS-Graph_Prepare_GraphServiceClient.cs
Last active October 7, 2019 16:40
Microsoft Graph C# .Net Core prepare GraphServiceClient
var clientId = "<AzureADAppClientId>";
var clientSecret = "<AzureADAppClientSecret>";
var redirectUri = "<AzureADAppRedirectUri>";
var authority = "https://login.microsoftonline.com/<AzureADAppTenantId>/v2.0";
var cca = ConfidentialClientApplicationBuilder.Create(clientId)
.WithAuthority(authority)
.WithRedirectUri(redirectUri)
.WithClientSecret(clientSecret)
.Build();
@BrianTJackett
BrianTJackett / PS-Get_All_Sites_SPO.ps1
Created July 31, 2018 15:44
Get all sites from SharePoint Online using SPO Management Shell commands.
Connect-SPOService -Url '<tenantAdminUrl>'
Get-SPOSite -Limit all -IncludePersonalSite $true
@BrianTJackett
BrianTJackett / CS-CSOM_Traverse_All_Sites_SPO.txt
Last active September 30, 2021 12:08
Traverse all sites in SharePoint Online using C# CSOM.
List <SiteProperties> list = new List <SiteProperties>();
SPOSitePropertiesEnumerable ssp = null;
SPOSitePropertiesEnumerableFilter sspFilter = new SPOSitePropertiesEnumerableFilter();
SharePointOnlineCredentials creds = new SharePointOnlineCredentials("myUsernameGoesHere", securePassword);
using (ClientContext cc = new ClientContext("myURLGoesHere"))
{
cc.Credentials = creds;