Skip to content

Instantly share code, notes, and snippets.

View XPlantefeve's full-sized avatar

Xavier Plantefève XPlantefeve

View GitHub Profile
# (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) {
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
<#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 September 4, 2019 09:44
Restore files from OVH Cloud Archive
#!/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 January 24, 2023 09:55
getting Active Directory info through ADSI
# 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 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
)
@XPlantefeve
XPlantefeve / WinHttpProxySettings.ps1
Last active April 29, 2024 16:29
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
#
# 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 `
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 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.