Skip to content

Instantly share code, notes, and snippets.

View jformacek's full-sized avatar

Jiri Formacek jformacek

View GitHub Profile
@jformacek
jformacek / HTTPServer.ps1
Created February 27, 2021 10:54 — forked from jakobii/HTTPServer.ps1
A Basic Powershell Webserver
# You Should be able to Copy and Paste this into a powershell terminal and it should just work.
# To end the loop you have to kill the powershell terminal. ctrl-c wont work :/
# Http Server
$http = [System.Net.HttpListener]::new()
# Hostname and port to listen on
$http.Prefixes.Add("http://localhost:8080/")
@jformacek
jformacek / Manage-MFA.ps1
Created February 3, 2021 10:13
Script for simple management of state of MFA enrollment of user
<#PSScriptInfo
.VERSION 1.5
.GUID ad963a82-8f68-4212-8a1d-dfbcceb60f52
.AUTHOR jiri.formacek@greycorbel.com
.COMPANYNAME GreyCorbel
@jformacek
jformacek / AdditionalLdapControls.cs
Last active December 25, 2021 19:08
Source code for additional LDAP controls that does not come with System.DirectoryServices.Protocol assembly, but might be useful
namespace System.DirectoryServices.Protocols
{
public class LdapServerLinkTtlControl : DirectoryControl
{
public LdapServerLinkTtlControl()
: base("1.2.840.113556.1.4.2309", (byte[]) null, true, true)
{
}
}
@jformacek
jformacek / jwt-bearer-login.ps1
Last active June 8, 2023 15:26
Login via urn:ietf:params:oauth:client-assertion-type:jwt-bearer raw flow from PowerShell without external dependencies
Function Login-WithCertificate
{
<#
Code shows login with certificate and retrieval of access token for Azure/O365 service (such as keyvault or Graph)
No dependencies on any libraries - just standard .NET Framework runtine (4.6 and higher) makes it suitable for easy
hosting on backends.
#>
Param
(
[Parameter()]
@jformacek
jformacek / LoginServicePrincipalInRunbook.ps1
Last active October 14, 2020 10:10
This code shows how to get access token for various resources as service principal that is associated with Azure Automation account.
<#
Code shows login with certificate for automation account RunAs connection, however, can be used to login with any certificate
Just update line that finds/retrieves the certificate and pass the certificate along with approriate appId for your app to login logic
#>
Param
(
[Parameter(Mandatory=$true)]
#Resource identifier, such as https://graph.microsoft.com
[string]$ResourceURI,
[Parameter(Mandatory=$false)]