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 Invoke-SqlSelect { | |
<# | |
.DESCRIPTION | |
This is a re-usable function that makes a connection to the database and retrieves a result set. | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory, Position = 0)] | |
[string] | |
$Command, |
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
namespace PSFSharp | |
open System.Management.Automation | |
open System.Management.Automation.Internal | |
[<Cmdlet(VerbsLifecycle.Invoke, "ConditionalAction", | |
ConfirmImpact = ConfirmImpact.Medium, SupportsShouldProcess = true)>] | |
[<Alias("?!")>] | |
type InvokeConditionalActionCommand() = | |
inherit PSCmdlet() |
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
Get-Content -Path $File | ForEach-Object { | |
if ($_ -match '(?<MethodName>\w+)\((<Arguments>.*?)\) *(?={)') { | |
$matches['Method'] = $matches[0] | |
$matches.Remove(0) | |
[PSCustomObject]$matches | |
} | |
} |
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 prompt { | |
$Success = $? | |
$ConsoleWidth = ($host.UI.RawUI.WindowSize.Width, $Host.UI.RawUI.BufferSize.Width -gt 0)[0] | |
$Escape = "`e[" | |
$EndEscape = "m" | |
$Slash = [IO.Path]::DirectorySeparatorChar | |
$Path = $ExecutionContext.SessionState.Path.CurrentLocation | |
$CurrentFolder = Split-Path -Path $Path -Leaf | |
$Host.UI.RawUI.WindowTitle = "PS $Path" |
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
$string = 'hostname.database.table.schema' | |
if ($string -match '(?<Hostname>\w+)\.(?<Database>\w+)\.(?<Table>\w+)\.(?<Schema>\w+)') { | |
$matches.Remove(0) | |
[PSCustomObject]$matches | |
} |
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
internal static float GetEnclosedArea(this SKPath path) | |
{ | |
SKRect bounds = path.TightBounds; | |
var boundedArea = bounds.Width * bounds.Height; | |
var totalPoints = 10000; | |
var enclosedPoints = 0; | |
for (float x = bounds.Left; x < bounds.Right; x += bounds.Width / (float)Math.Sqrt(totalPoints)) | |
{ | |
for (float y = bounds.Top; y < bounds.Bottom; y += bounds.Height / (float)Math.Sqrt(totalPoints)) |
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
// Generic this --> multiple type handling | |
internal static bool TryConvertSByte(double value, out sbyte outValue) | |
{ | |
if (value < sbyte.MinValue || value > sbyte.MaxValue) | |
{ | |
outValue = 0; | |
return false; | |
} |
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
$Module = New-Module -Name 'ImportMe' -ScriptBlock { | |
class TryMeException : System.Exception { | |
TryMeException() : base() {} | |
TryMeException([string]$Message) : base($Message) {} | |
} | |
$onremove = { | |
throw [TryMeException]::new("HOW DARE YOU STEAL THAT CAR") | |
} | |
$ExecutionContext.SessionState.Module.OnRemove += $onremove | |
} |
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 New-Shortcut { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory)] | |
[ValidateScript({ Test-Path -IsValid $_ })] | |
[string]$Path, | |
[Parameter(Mandatory, ValueFromPipeline)] | |
[ValidateScript({ Test-Path $_ })] | |
[string]$Target, |
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
$Properties = 'GivenName', 'Surname', 'Department', 'EmailAddress', 'Office' | |
Get-ADUser -Filter 'Department -like "*"' -Properties $Properties | | |
Select-Object -Property $Properties | | |
ConvertTo-Csv -NoTypeInformation | # Convert to CSV string data without the type metadata | |
Select-Object -Skip 1 | # Trim header row, leaving only data columns | |
Set-Content -Path "c:\emailaddress.csv" |