Skip to content

Instantly share code, notes, and snippets.

View gravejester's full-sized avatar

Øyvind Kallstad gravejester

View GitHub Profile
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) {
$a -foobar $b # should not match
Invoke-Something -foobar
Invoke-Something -foobar value
Invoke-Something -foobar:$true
Invoke-Something -foobar: $true
Invoke-Something -p1 v1 -p2 10 -p3 'value' -switch -verbose
Invoke-Something -p1 {Get-Something}
Get-Something -p1 'Input' | Invoke-Something -p1 @('one','two','three') | ForEach-Object {$_}
Invoke-Something -parameter1 'value' `
-parameter2 10 `
$adPath = 'OU=Users,OU=Dev,DC=test,DC=local'
$adDomain = 'test.local'
$userPassword = 'aV3ryl0ng-and.securePASSWORD!!'
$users = Get-RandomUser -Amount 30 -Nationality gb,uk -ExcludeFields picture | Select-Object -ExpandProperty results
foreach ($user in $users) {
$newUserProperties = @{
Name = "$($user.name.first) $($user.name.last)"
GivenName = $user.name.first
function Get-RandomUser {
<#
.SYNOPSIS
Generate random user data.
.DESCRIPTION
This function uses the free API for generating random user data from https://randomuser.me/
.EXAMPLE
Get-RandomUser 10
.EXAMPLE
Get-RandomUser -Amount 25 -Nationality us,gb -Format csv -ExludeFields picture
# testing psInlineProgress
$null = Start-Transcript -Path C:\users\grave\Scripts\InlineProgressBar\transcript.txt
Write-Host ''
# Simple progressBar
Write-Host 'Example of default behaviour' -ForegroundColor Magenta
Write-Host ''
$collection = 0..12
$count = 0