Skip to content

Instantly share code, notes, and snippets.

View gravejester's full-sized avatar

Øyvind Kallstad gravejester

View GitHub Profile

Keybase proof

I hereby claim:

  • I am gravejester on github.
  • I am okallstad (https://keybase.io/okallstad) on keybase.
  • I have a public key ASBM-6vpDIBHoXbDogydKGLwjT3NC_7iy7EtFJ6ApHawSwo

To claim this, I am signing this object:

@gravejester
gravejester / CRC.ps1
Last active November 28, 2021 22:48
function Get-CRC32 {
<#
.SYNOPSIS
Calculate CRC.
.DESCRIPTION
This function calculates the CRC of the input data using the CRC32 algorithm.
.EXAMPLE
Get-CRC32 $data
.EXAMPLE
$data | Get-CRC32
# Add custom type with static method
Add-Type -MemberDefinition @"
public static string SayHello()
{
string Hello = "Hello";
return Hello;
}
"@ -Name Stuff -Namespace My
# Define custom function calling my custom type
function Test-WebRequest {
<#
.SYNOPSIS
Test web request.
.DESCRIPTION
This function can be used to test a web request to a URI. It functions similarly to Test-Path and will either return
True or False.
.EXAMPLE
Test-WebRequest 'google.com'
This should return True.
function Invoke-StreamData {
[CmdletBinding()]
param (
[switch] $ShowWarning,
[switch] $ShowError
)
Write-Host "This is written to the host"
Write-Verbose "This is written to the verbose stream"
Write-Output "This is written to the output stream"
function ConvertTo-GUID {
[CmdletBinding()]
param (
[Parameter(Position = 0, ValueFromPipeline = $true)]
[string] $ImmutableId
)
try {
$byteArray = [Convert]::FromBase64String($ImmutableId)
$newGuid = [Guid]::new($byteArray)
function ConvertTo-ImmutableId {
[CmdletBinding()]
param (
[Parameter(Position = 0, ValuefromPipeline = $true, ValueFromPipelinebyPropertyName = $true)]
[Guid]$ObjectGUID
)
try {
$byteArray = $ObjectGUID.ToByteArray()
$immutableId = [Convert]::ToBase64String($byteArray)
function Get-ObjectPropertyInfo {
#Requires -Version 3
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, Position = 0)]
$InputObject
)
$objectProperties = $InputObject | Get-Member -MemberType '*Property*'
Write-Verbose -Message "Object have $($objectProperties.Count) properties."
function Get-GeoLocation {
<#
.SYNOPSIS
Get current location.
.DESCRIPTION
This function tries to get the latitude and longitude coordinates of the current location,
and will look up those coordinates on OpenStreetMap to get address information.
.EXAMPLE
function Get-DPMActiveOwner {
[CmdletBinding()]
param (
[Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[string[]] $Path
)
PROCESS {
foreach ($thisPath in $Path) {