Skip to content

Instantly share code, notes, and snippets.

View JustinGrote's full-sized avatar

Justin Grote JustinGrote

View GitHub Profile
@JustinGrote
JustinGrote / Resolve-AzureADUsers.csv
Created June 13, 2018 17:00
Take a delta sync from Azure AD Connect and find out what users would be affected by performing the operation
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
#Requires -Version 3
function ConvertFrom-AADConnectDN {
<#
.SYNOPSIS
Takes an encoded DN from Azure AD Connect and returns the immutableID
.EXAMPLE
"CN={7961504952763968323075686E79557A4D76547058513D3D}" | ConvertFrom-AADConnectDN
@JustinGrote
JustinGrote / Get-NetworkDeviceConfig.ps1
Created June 22, 2018 20:56
Get the running configuration from a network device using Powershell. Supports Cisco and JunOS
#requires -module Posh-SSH
param (
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)][String]$Computername,
[ValidateSet("Cisco","JunOS")]
[Parameter(ValueFromPipelineByPropertyName)][String]$DeviceType = "Cisco",
[String]$RepositoryPath = $home\desktop,
[PSCredential]$Credential
)
@JustinGrote
JustinGrote / Install-BuildHelperModuleItem
Created June 25, 2018 18:01
"Install-Module" Equivalent that works in PS v3 and v4
#Fetch Build Helper Modules using Install-ModuleBootstrap script (works in PSv3/4)
#The comma in ArgumentList a weird idiosyncracy to make sure a nested array is created to ensure Argumentlist
#doesn't unwrap the buildhelpermodules as individual arguments
#We suppress verbose output for master builds (because they should have already been built once cleanly)
foreach ($BuildHelperModuleItem in $BuildHelperModules) {
if (-not (Get-module $BuildHelperModuleItem -listavailable)) {
write-verbose "Build Initialization: Installing $BuildHelperModuleItem from Powershell Gallery to your currentuser module directory"
if ($PSVersionTable.PSVersion.Major -lt 5) {
write-verboseheader "Bootstrapping Powershell Module: $BuildHelperModuleItem"
@JustinGrote
JustinGrote / Fortimanager.psm1
Last active October 5, 2022 12:22
Basic Framework for a Fortimanager Powershell Module
function Connect-FMServer {
param (
#The hostname of your Fortimanager
[Parameter(Mandatory)][Alias("Server","Hostname")][String]$ComputerName,
#Your username and password. Must be enabled for remote API access
[Parameter(Mandatory)][PSCredential]$Credential,
#Disable SSL Checks. THe name on the certificate must still match what you specified for -ComputerName
[Switch]$Force
)
@JustinGrote
JustinGrote / Get-PRTGDeviceSysInfo.ps1
Created August 15, 2018 20:25
Function to retrieve PRTG Device System Information
#requires -module PrtgAPI -version 5
using namespace PrtgAPI
function Get-PRTGDeviceSysInfo {
<#
.SYNOPSIS
Retrieve PRTG Device System Information via the (undocumented) API.
.EXAMPLE
Get-PRTGDeviceSysInfo -ID 13926
@JustinGrote
JustinGrote / ConvertTo-NiceXML.ps1
Created October 2, 2018 20:49
Take a Powershell Object and convert it into a more friendly version of XML useful for data interchange
function ConvertTo-NiceXML {
[CmdletBinding()]
param (
#Object to Input
[Parameter(ValueFromPipeline)]$InputObject,
#Name of the root document node. Defaults to "Objects"
$RootNodeName = "Objects"
)
begin {
@JustinGrote
JustinGrote / Measure-MemoryUse.ps1
Created October 19, 2018 23:21
Function to measure a command's memory usage, and if Garbage Collection is working properly
#requires -version 5 -module PoshRSJob
function Measure-MemoryUse ([ScriptBlock]$ScriptBlock,$CallOperator) {
function GetMem([switch]$RunGC) {
[int]([gc]::GetTotalMemory($RunGC) / 1MB)
}
$result = [ordered]@{}
$result.ScriptBlock = $ScriptBlock
@JustinGrote
JustinGrote / Get-AzFunctionsKeyVaultCredential.ps1
Last active October 31, 2018 05:03
Fetch Credentials from an Azure Key Vault in Azure Functions Powershell using a Managed Service Identity
<#
.SYNOPSIS
Fetches Azure Key Vault credentials using a managed service identity with a more lightweight approach than the Az powershell module
.EXAMPLE
.\Get-AzFunctionsKeyVaultCredential.ps1 -Identifier https://MYKEYVAULTNAME.vault.azure.net/secrets/MYSECRETNAME
.EXAMPLE
.\Get-AzFunctionsKeyVaultCredential.ps1 -KeyVaultName MYKEYVAULTNAME -KeyNme MYSECRET
.OUTPUT
System.Management.Automation.PSCredential
@JustinGrote
JustinGrote / AzureAutomationDSC.build.ps1
Last active November 13, 2018 20:37
Azure Automation DSC: Automatic Upload and Compile for VS Code
#requires -version 5
#requires -module BuildHelpers,InvokeBuild,Az.Automation,Az.Profile
#Azure Automation
#Uses Invoke-Build (https://github.com/nightroman/Invoke-Build)
param (
#Where to perform the building of the module. Defaults to "Release" under the project directory. You can specify either a path relative to the project directory, or a literal alternate path.
[String]$BuildOutputPath,
#The azure subscription to use
@JustinGrote
JustinGrote / Reset-ADUserPermissions.ps1
Last active December 6, 2018 22:06
Reset Active Directory User Permissions to Inherited Defaults
function Reset-ADUserPermissions {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline)][String]$UserName
)
process {
$rootDSE = Get-ADRootDSE
$defaultSDDL = (Get-ADObject -SearchBase $RootDSE.schemaNamingContext -ldapFilter '(&(Objectclass=classSchema)(name=user))' -Properties defaultSecurityDescriptor).defaultsecuritydescriptor