Skip to content

Instantly share code, notes, and snippets.

View XPlantefeve's full-sized avatar

Xavier Plantefève XPlantefeve

View GitHub Profile
@XPlantefeve
XPlantefeve / LICENSE.txt
Last active April 12, 2022 10:02
Powershell Gist management CMDlets
MIT License
Copyright (c) 2016 Xavier Plantefeve
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@XPlantefeve
XPlantefeve / MaintenanceWindowFunctions.ps1
Last active June 13, 2016 09:15
A couple of quickly done functions to handle local CCM maintenance windows.
<#
MIT License
Copyright (c) 2016 Xavier Plantefeve
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@XPlantefeve
XPlantefeve / New-ExcelDocument.ps1
Created June 15, 2016 11:44
Barebone excel creation + CSV import method. Basis for further work.
#region ExcelFunctions
function Get-NormalizedPath ( $Path ) {
if ( ( Split-Path $Path ) -match '^(\.|)$' ) {
$Path = Join-Path -Path ( Get-Location ) -ChildPath ( Split-Path -Path $Path -Leaf )
}
return $Path
}
$MethodImportCSVtoSheet = {
function Get-FolderSizeRC($Path) {
if ( robocopy $Path c:\dummy /e /r:0 /w:0 /b /BYTES /nfl /ndl /np /njh /l | ? { $_ -match 'Bytes :\s*(?<size>\S+)' } ) { return [int64]$Matches.size }
}
function Get-FolderSizePS($Path) {
return ( ls -Recurse -Path $Path -Force | measure -Property length -Sum ) | select -ExpandProperty Sum
}
function test($Path) {
Write-Host -Object "Testing $Path" -ForegroundColor Cyan
Topic: NBA All Stars
Owners: Foo Owners
Users: User 1
Users: User 2
Topic: NFL MVPs
Owners: Bar Owners
Users: Tony Stark
Users: Mitch Hedberg
Users: Someone Else
Topic: NBA MVPs
@XPlantefeve
XPlantefeve / Get-LastDOW.ps1
Created July 13, 2017 12:45
Get date for last <day of week>
function Get-LastDOW {
<#
.SYNOPSIS
Returns the date of the last day of week you select.
.DESCRIPTION
Get-LastDOW will return the date of the last day of the week you select,
up to one week in the past (between one week ago and yesterday). Useful,
as an example, to search in logs for events only happening once a week.
Function Get-Profiles
{
<#
.SYNOPSIS
Gives a list of locally saved user profiles.
.DESCRIPTION
Gets a list of locally used profiles according to the registry and
returns an object with information about the profile.
# The following is an example, it's not a function, it's not meant to be run
# as is, I just wrote it to show how creating a scheduled tak on an event
# can be done in PowerShell. I wrote a small post about how it came to be, that
# can be read at https://xavier.plantefeve.fr/posts/SchdTskOnEvent
$class = Get-cimclass -ClassName MSFT_TaskEventTrigger -Namespace root/Microsoft/Windows/TaskScheduler
$trigger = $class | New-CimInstance -ClientOnly
$trigger.Enabled = $true
$trigger.Subscription = '<QueryList><Query Id="0" Path="Microsoft-Windows-NetworkProfile/Operational"><Select `
@XPlantefeve
XPlantefeve / WinHttpProxySettings.ps1
Last active April 28, 2026 09:23
netsh winhttp * proxy, but in PowerShell
# Quick & dirty. Basic error checking. It works where I needed it.
#
# Documentation used:
# - ProcMon
# - https://securelink.be/blog/windows-proxy-settings-explained/
# - https://docs.microsoft.com/en-us/windows/desktop/api/Winhttp/ns-winhttp-__unnamed_struct_3
# - https://github.com/vbfox/proxyconf/blob/master/README.md
# - https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/managing-bit-flags-part-1
# - https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_enum
#
@XPlantefeve
XPlantefeve / Do-Something.ps1
Last active February 14, 2019 09:17
Do-Something, the lazy typist way
# Laziness is a great gift
# Every function will have the exact same definition, so we won't bother
# copypasting.
$FunctionBody = {
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
[object[]]$inputObject
)