This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # 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/") | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <#PSScriptInfo | |
| .VERSION 1.5 | |
| .GUID ad963a82-8f68-4212-8a1d-dfbcceb60f52 | |
| .AUTHOR jiri.formacek@greycorbel.com | |
| .COMPANYNAME GreyCorbel | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | namespace System.DirectoryServices.Protocols | |
| { | |
| public class LdapServerLinkTtlControl : DirectoryControl | |
| { | |
| public LdapServerLinkTtlControl() | |
| : base("1.2.840.113556.1.4.2309", (byte[]) null, true, true) | |
| { | |
| } | |
| } | |
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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()] | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <# | |
| 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)] |