Skip to content

Instantly share code, notes, and snippets.

View neil-sabol's full-sized avatar

Neil Sabol neil-sabol

  • New Mexico, USA
View GitHub Profile
function parse-m365-auditlogsearch-results {
# Collect the input and output files
Param (
[Parameter(Mandatory=$true)]
[string] $auditlogsearchresultfile = "",
[Parameter(Mandatory=$true)]
[string] $outputcsvfilepath = ""
)
# Import the Audit Log Search Result CSV file exported from Microsoft Purview
@neil-sabol
neil-sabol / onetimesecret-api-random-credential-link-example.ps1
Created April 5, 2020 00:27
See https://blog.neilsabol.site/post/onetimesecret-api-powershell-cli-basic-example-one-time-secret/ . This snippet uses Invoke-RestMethod and the OneTimeSecret API to generate a random password then output the password and secret link to retrieve it.
@neil-sabol
neil-sabol / MgGraph-BulkRemoveDirectAssignedLicense.ps1
Last active February 1, 2024 10:47 — forked from mrik23/MSOL-BulkRemoveDirectAssignedLicense.ps1
Remove in bulk direct assigned license to users who have group assigned license with the Microsoft Graph (MgGraph) PowerShell module
<#
Modified version of mrik23's MSOL-BulkRemoveDirectAssignedLicense.ps1 (https://gist.github.com/mrik23/2ed37ce0c7c4a79605bdcf052e29b391)
MSOL-BulkRemoveDirectAssignedLicense.ps1 was a modified version of a script from Microsoft Documentation.
Ref: https://docs.microsoft.com/en-us/azure/active-directory/active-directory-licensing-ps-examples
Removed the part that checks if the users is assigned more products than the group assigned license.
Added connection part and help to find Sku and Group Object ID.
This script requires the Microsoft Graph (MgGraph) PowerShell module.
#>
Import-Module Microsoft.Graph.Users
# Install the PowerShell LDAP module
Install-Module -Name Ldap
# Create an Active Directory connection via LDAP, replacing 'CN=binduser,OU=Accounts,DC=ad,DC=contoso,DC=com'
# with a real user in the directory and specifying the user's password when prompted
# See https://github.com/replicaJunction/Ldap/blob/master/docs/en-US/Get-LdapConnection.md
$binduser = 'CN=binduser,OU=Accounts,DC=ad,DC=contoso,DC=com'
$connection = Get-LdapConnection -Server 'ad.contoso.com' -Port 636 -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $binduser,(Read-Host -AsSecureString -Prompt "Enter password"))
# Specify a large AD group and search base to query
# Specify the FQDNs of the source and destination distribution points
$sourceDP = "MEMCMDP1.contoso.com"
$destDP = "MEMCMDP2.contoso.com"
# Suppress error messages (usually because content already exists on the destination)
$ErrorActionPreference = "SilentlyContinue"
# Get all content from the source DP
# See https://learn.microsoft.com/en-us/powershell/module/configurationmanager/get-cmdeploymentpackage?view=sccm-ps
Get-CMDeploymentPackage -DistributionPointName $sourceDP | %{
@neil-sabol
neil-sabol / Get-ChildItem-Path.Tests.ps1
Last active March 7, 2021 15:11
See https://blog.neilsabol.site/post/deleting-specific-log-files-by-extension-older-than-days/. This Pester snippet demonstrates the use of -Path vs. -LiteralPath with the Get-ChildItem PowerShell cmdlet. Prerequisites: Pester 5+ (Install-Module -Name Pester -Force -SkipPublisherCheck), PowerShell 5+, Windows 2012+. Once the prerequisites are in…
# ###############################
# Get-ChildItem-Path.Tests.ps1
# https://blog.neilsabol.site/post/deleting-specific-log-files-by-extension-older-than-days/
# Neil Sabol
# neil.sabol@gmail.com
# ###############################
# Define test parameters
$script:testPath = "C:\Temp"
$script:testLiteralPath = "\\?\C:\Temp"
@neil-sabol
neil-sabol / Duo-PSModule-Azure-Automation-RunBook-User-Sync-Example.ps1
Created February 6, 2021 18:16
See https://blog.neilsabol.site/post/importing-duo-psmodule-mfa-powershell-module-azure-automation. This snippet demonstrates securely providing Duo integration details to the Duo-PSModule in Azure Automation using encrypted Automation Variables and forcing a directory synchronization cycle for all Duo users.
# Get Duo integration details from Automation Variables
$duoiKey = Get-AutomationVariable -Name MyDuoiKey
$duosKey = Get-AutomationVariable -Name MyDuosKey
$duoApiHost = Get-AutomationVariable -Name MyDuoHostname
$duoDirID = Get-AutomationVariable -Name MyDuoDirectoryID
# Build the $DuoOrgs hashtable from retrieved Automation Variables
[string]$DuoDefaultOrg = "Personal"
[Hashtable]$DuoOrgs = @{
Personal = [Hashtable]@{
@neil-sabol
neil-sabol / Duo-PSModule-Azure-Automation-RunBook-Auth-Example.ps1
Created February 6, 2021 18:08
See https://blog.neilsabol.site/post/importing-duo-psmodule-mfa-powershell-module-azure-automation. This snippet demonstrates securely providing Duo integration details to the Duo-PSModule in Azure Automation using encrypted Automation Variables.
# Get Duo integration details from Automation Variables
$duoiKey = Get-AutomationVariable -Name MyDuoiKey
$duosKey = Get-AutomationVariable -Name MyDuosKey
$duoApiHost = Get-AutomationVariable -Name MyDuoHostname
$duoDirID = Get-AutomationVariable -Name MyDuoDirectoryID
# Build the $DuoOrgs hashtable from retrieved Automation Variables
[string]$DuoDefaultOrg = "Personal"
[Hashtable]$DuoOrgs = @{
Personal = [Hashtable]@{
@neil-sabol
neil-sabol / ykpersonalize-yubikey-generate-static-password.ps1
Last active January 31, 2021 13:17
See https://blog.neilsabol.site/post/yubikey-personalization-tool-yubico-powershell-command-cli-program-random-static-password-commandline/#closing-thoughts. This snippet uses the ykpersonalize (YubiKey Personalization Tool) command to generate a new static password on the Yubikey.
# Create an alias for ykpersonalize pointing the the location it is downloaded to
set-alias ykpersonalize "$env:localappdata\Programs\Yubico\bin\ykpersonalize.exe"
# Generate a random hex (AES key) to serve as entropy (randomness source) for ykpersonalize
$RandomHex = (((32)|%{((1..$_)|%{('{0:X}' -f (random(16)))})}) -Join "").ToLower()
# Run ykpersonalize to generate a random static password in Yubikey's config slot 2
ykpersonalize -2 -a"$RandomHex" -ostatic-ticket -oshort-ticket -ostrong-pw1 -ostrong-pw2 -y
@neil-sabol
neil-sabol / ykman-yubikey-static-password-reset-example.ps1
Last active January 31, 2021 13:17
See https://blog.neilsabol.site/post/yubikey-personalization-tool-yubico-powershell-command-cli-program-random-static-password-commandline/ . This snippet uses the ykman command to generate a new static password on the Yubikey, then reset the password of the user running the PowerShell session to the new static password (requires pressing the bu…
# Create an alias for ykman pointing the the install location
set-alias ykman "$env:programfiles\Yubico\YubiKey Manager\ykman.exe"
# Provide an opportunity to insert the yubikey before continuing
Read-Host -Prompt "Ensure Yubikey is inserted then press Enter to continue"
# Add a new line for formatting/tidiness
write-host " "
# Run ykman to generate the static password on the Yubikey (in slot 2)