Skip to content

Instantly share code, notes, and snippets.

$LUP_DEEP = 0x0001 # Queries deep as opposed to just the first level.
$LUP_CONTAINERS = 0x0002 # Returns containers only.
$LUP_NOCONTAINERS = 0x0004 # Do not return containers.
$LUP_NEAREST = 0x0008 # If possible, returns results in the order of distance. The measure of distance is provider specific.
$LUP_RETURN_NAME = 0x0010 # Retrieves the name as lpszServiceInstanceName.
$LUP_RETURN_TYPE = 0x0020 # Retrieves the type as lpServiceClassId.
$LUP_RETURN_VERSION = 0x0040 # Retrieves the version as lpVersion.
$LUP_RETURN_COMMENT = 0x0080 # Retrieves the comment as lpszComment.
$LUP_RETURN_ADDR = 0x0100 # Retrieves the addresses as lpcsaBuffer.
$LUP_RETURN_BLOB = 0x0200 # Retrieves the private data as lpBlob.
@CosmosKey
CosmosKey / Measure-Script.ps1
Created December 6, 2016 13:08
Measure-Script
#region Profiler
class Profiler
{
[System.Diagnostics.Stopwatch[]]$StopWatches
Profiler([System.Management.Automation.Language.IScriptExtent]$extent)
{
$lines = $extent.EndLineNumber
$this.StopWatches = [System.Diagnostics.Stopwatch[]]::new($lines)
for ($i = 0; $i -lt $lines; $i++)
{
New-Module -Name tt -ScriptBlock {
$ErrorActionPreference="stop"
function t1 {
[CmdletBinding()]
param()
try {
"trying"
Get-Content c:\TheFileWhichDoesNotExist.txt
"Yiiihaaaa"
} catch {
class ScriptBlockInjectorVisitor : System.Management.Automation.Language.ICustomAstVisitor
{
[scriptblock]$BeforeScriptBlock = $null
[scriptblock]$ReplacementScriptBlock = $null
[scriptblock]$AfterScriptBlock = $null
[int]$Index
[System.Object] VisitElement([object]$element) {
if ($element -eq $null) {
return $null
}
#################################### BEGIN ##############################################
$Title = "My Doc"
$lab = {
########## Module
###### Task - Set an alias
#### Description
## Set an alias using Set-Alias and test it.
### Example:
$ModuleName = "MyTestModule"
$userModulePath = $env:PSModulePath.Split(";") -like "*\$env:USERNAME\*"
New-Item -Path "$userModulePath\$ModuleName" -ItemType Directory -Force | Out-Null
{function Get-Zero{0}function Get-One{1}}|Set-Content "$userModulePath\$ModuleName\$ModuleName.psm1"
New-ModuleManifest -Path "$userModulePath\$ModuleName\$ModuleName.psd1" -RootModule "$ModuleName.psm1" -FunctionsToExport "Get-Zero"
Get-Module -ListAvailable -Name $ModuleName
Get-Zero
@CosmosKey
CosmosKey / ConsoleCursorLab.ps1
Created August 26, 2017 10:18
Console Cursor Lab, handling cursors in [console]
Write-Host "Done Name State HasData"
$global:js = [System.Collections.ArrayList]::new()
for($i=0;$i -lt 10;$i++){
$j = Start-Job {"JOB" + $using:i;Start-Sleep -Milliseconds (Get-Random -Maximum 3000 -Minimum 0) } -Name "MyJob-$i"
$j | Add-Member -Name CursorTop -MemberType NoteProperty -Value ([console]::CursorTop) -Force
[void]$js.Add($j)
Write-Host "x " -ForegroundColor Red -NoNewline
Write-Host ("{0} {1} {2}" -f $j.Name,$j.State,$j.HasMoreData)
}
[console]::CursorVisible = $false
@CosmosKey
CosmosKey / SelectBuildingAndOfficeForm.ps1
Last active December 28, 2017 10:23
SelectBuildingAndOfficeForm.ps1 A piece of DropDown Forms sample code
# DropDown Data
$office = @{
'HQ' = 'Ground floor','1st floor','2nd floor','3rd floor'
'Garage' = 'Shop floor','Office'
'Sales office' = 'Ground floor','1st floor'
}
# Load assemblies
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$Name = "MSFT-Office 365 Enterprise E1"
$groupSearcher = [adsisearcher]"(samaccountname=$Name)"
$group = $groupSearcher.FindOne()
$memberSearch = [adsisearcher]::new($group.GetDirectoryEntry(),"(&(objectClass=user)(objectCategory=Person))",[string[]]'samaccountname','base')
$memberSearch.AttributeScopeQuery = "member";
foreach($member in $memberSearch.FindAll())
{
$member.Properties['samaccountname']
}
@CosmosKey
CosmosKey / Get-CertificateChain.ps1
Created September 9, 2017 14:07
Get-CertificateChain.ps1
Function Get-CertificateChain {
param(
[string]$server=$(throw "Mandatory parameter -Server is missing."),
[int]$port=$(throw "Mandatory parameter -Port is missing."),
[switch]$ToBase64
)
$code=@"
using System;
using System.Collections;
using System.Net;