Skip to content

Instantly share code, notes, and snippets.

Avatar

Xavier Plantefève XPlantefeve

View GitHub Profile
View Import-BEncoded.ps1
# (very) quick and (very) dirty bencoding converter.
# I actually did not now what bencoding was and reverse engineered the few
# files I needed information about.
param(
[Parameter(Mandatory)]
[string[]]$Path
)
function vo ($hash) {
View SubfoldersSizeReport.ps1
function Get-HumanReadableSize {
<#
.SYNOPSIS
Outputs a human readable version of a file size
.DESCRIPTION
This function rounds the value of the given file size to the nearest relevant
multiplier prefix (Gb, Mb, or Kb)
.INPUTS
long
.OUTPUTS
View Reset-PwdLastSet.ps1
<#PSScriptInfo
.VERSION 1.0
.GUID 021fb1d9-6c04-4bea-983b-92e03d14963d
.AUTHOR Xavier Plantefeve
.COPYRIGHT 2020 Xavier Plantefeve
.TAGS ActiveDirectory,Password
.LICENSEURI https://opensource.org/licenses/MIT
.PROJECTURI https://gist.github.com/XPlantefeve/9b1e987baf1024149edad58bb88490b2
.EXTERNALMODULEDEPENDENCIES ActiveDirectory
#>
@XPlantefeve
XPlantefeve / restoreOVHCloudArchive
Last active Sep 4, 2019
Restore files from OVH Cloud Archive
View restoreOVHCloudArchive
#!/bin/bash
dirname=$(dirname $0)
basename=$(basename $0)
conffile="${basename%.*}.conf"
if [ -f "$dirname/$conffile" ]
then
conffile="$dirname/$conffile"
. "$conffile"
@XPlantefeve
XPlantefeve / filter_to_ldapfilter.ps1
Last active Jun 11, 2020
getting Active Directory info through ADSI
View filter_to_ldapfilter.ps1
# Quick and very dirty PS filter to LDAP filters translation
function Format-LdapEscaped ($string,[switch]$wildcard) {
Switch -Regex ($string.Trim()) {
'^"(?<str>.*)"$' { $string = $Matches.str -replace '`"','"' }
"^'(?<str>.*)'$" { $string = $Matches.str -replace "''","'" }
}
$string = $string -replace '\\5c','\'
$string = $string -replace '\\00','NUL'
@XPlantefeve
XPlantefeve / Do-Something.ps1
Last active Feb 14, 2019
Do-Something, the lazy typist way
View Do-Something.ps1
# 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
)
@XPlantefeve
XPlantefeve / WinHttpProxySettings.ps1
Last active Feb 10, 2019
netsh winhttp * proxy, but in PowerShell
View WinHttpProxySettings.ps1
# 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
#
View CreateSchdTskOnEvent.ps1
# 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 `
View registryHives.ps1
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.
@XPlantefeve
XPlantefeve / Get-LastDOW.ps1
Created Jul 13, 2017
Get date for last <day of week>
View Get-LastDOW.ps1
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.