This file contains 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
class LCG | |
{ | |
hidden [long] | |
$factor = 1140671485 | |
hidden [long] | |
$offset = 12820163 | |
hidden [long] | |
$modulus = 16777216 |
This file contains 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 Get-WebExceptionBody | |
{ | |
param( | |
[int]$Last | |
) | |
if(-not $PSBoundParameters.ContainsKey('Last')){ | |
$Last = 1 | |
} |
This file contains 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
using namespace System | |
using namespace System.Net | |
using namespace System.Text | |
using namespace System.IO | |
class Test | |
{ | |
# Specify the URL to receive the request. | |
static Run([string[]]$arguments) | |
{ |
This file contains 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
Add-Type -AssemblyName System.Security | |
function Sign-XML { | |
Param ( [xml]$xml, [System.Security.Cryptography.X509Certificates.X509Certificate2]$certificate ) | |
[System.Security.Cryptography.xml.SignedXml]$signedXml = $NULL | |
$signedXml = New-Object System.Security.Cryptography.Xml.SignedXml -ArgumentList $xml | |
$signedXml.SigningKey = $certificate.PrivateKey | |
$keyInfo = New-Object System.Security.Cryptography.Xml.KeyInfo |
This file contains 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
using namespace System.Collections.Generic | |
# First we define our comparer | |
class SortPropertyFirstComparer : IComparer[string] | |
{ | |
[int]Compare([string]$a,[string]$b) | |
{ | |
if($a -ceq 'Property'){ | |
return -1 | |
} |
This file contains 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
# download and install https://github.com/IISResetMe/MeasureScript/tree/master/src | |
Import-Module MeasureScript | |
Measure-Script -ScriptBlock {# use a stopwatch to measure performance | |
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew() | |
# create a StringBuilder | |
$text = "" | |
# appending a string often |
This file contains 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
Add-Type @' | |
public struct StringWrapper | |
{ | |
string s; | |
public StringWrapper(string s){ this.s = s; } | |
public void Add(string suffix) | |
{ | |
s += suffix; | |
} |
This file contains 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
using System; | |
using System.IO; | |
using System.Runtime.InteropServices; | |
public class OleReader | |
{ | |
public OleReader(string filename, long offset = 0L) | |
{ | |
if (string.IsNullOrWhiteSpace(filename)) | |
{ |
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.Management.Automation; | |
namespace MyCmdlets | |
{ | |
[Cmdlet(VerbsData.Merge, "Object")] | |
public class MergeObjectCommand : PSCmdlet | |
{ | |
[Parameter(ValueFromPipeline = true, Mandatory = true)] |
This file contains 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 Update-ADPassword | |
{ | |
param( | |
[string]$Domain = $env:USERDOMAIN | |
) | |
try { | |
Add-Type -AssemblyName System.DirectoryServices.AccountManagement | |
$ctx = [System.DirectoryServices.AccountManagement.PrincipalContext]::new('Domain', $Domain) | |
$acc = [System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity($ctx, ($currCred = Get-Credential -Message 'Input your current credentials').UserName) |