Skip to content

Instantly share code, notes, and snippets.

View figueroadavid's full-sized avatar

David Figueroa figueroadavid

View GitHub Profile
@figueroadavid
figueroadavid / PowerShell-XAML-Template.ps1
Last active September 23, 2022 15:53 — forked from QuietusPlus/PowerShell-XAML-Template.ps1
Template: Use PowerShell to launch a .xaml file (MainWindow.xaml) designed within Visual Studio. It automatically removes attributes which are otherwise incompatible, so design in Visual Studio and launch your GUI without any additional steps. The template supports "Windows Presentation Foundation" and "Windows Forms" by default, add additional …
[cmdletbinding()]
param(
[parameter(Mandatory, ValueFromPipelineByPropertyName)]
[string]$FilePath
)
# .NET Framework classes
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
# XAML
@figueroadavid
figueroadavid / Invoke-WithImpersonation.ps1
Created December 21, 2021 21:53 — forked from jborean93/Invoke-WithImpersonation.ps1
Invoke a scriptblock in powershell with impersonation
# Copyright: (c) 2020, Jordan Borean (@jborean93) <[email protected]>
# MIT License (see LICENSE or https://opensource.org/licenses/MIT)
Function Invoke-WithImpersonation {
<#
.SYNOPSIS
Invoke a scriptblock as another user.
.DESCRIPTION
Invoke a scriptblock and run it in the context of another user as supplied by -Credential.

Credit: Mark Kraus
Website: https://get-powershellblog.blogspot.com

Collection Type Guidance

When to use what

  • Use Arrays if you know the element types and have a fixed length and/or known-up-front collection size that will not change.
  • Use ArrayList if you have an unkown collection size with either unknown or mixed type elements.
  • Use a Generic List when know the type of the elements but not the size of the collection.
  • Use a HashTable if you are going to do key based lookups on a collection and don't know the object type of the elements.
  • Use a Dictionary<TKey, TValue> you are going to do key based lookups on a collection and you know the type of the elements.
  • Use a HashSet when you know the type of elements and just want unique values and quick lookups and assignmnets.