Skip to content

Instantly share code, notes, and snippets.

@LxLeChat
LxLeChat / jsontotype.ps1
Last active April 8, 2022 21:12
Json To Typed Object in powershell
# https://stackoverflow.com/questions/69848181/trying-to-deserialize-json-to-typed-object-in-powershell
$RandomJson = @'
{
"Name" : "Plop",
"Id" : 1
}
'@
Class MonJsonToObject {
[String]$Name
@LxLeChat
LxLeChat / visitor.ps1
Created January 22, 2022 19:53 — forked from Jawz84/visitor.ps1
visitor pattern AstVisitor2
using namespace System.Management.Automation.Language;
class AstCommandVisitor : AstVisitor2 {
[string[]] hidden $result
[string[]] GetResults() {
return $this.result
}
# See all Method names you can override:
$web = [HtmlAgilityPack.HtmlWeb]::new()
$htmldoc = $web.Load("https://www.twitch.tv/jmundle/about")
$htmldoc.DocumentNode.SelectNodes("//figure")
@LxLeChat
LxLeChat / test.ps1
Last active February 5, 2020 22:58
hop
$results = [PSCustomObject]@{
Id = 2992080
Language = "All"
Title = "Security Update for Microsoft ASP.NET MVC 5.0 (KB2992080)"
}
$hash = @{
id = 2992080
language = "All"
title = "Security Update for Microsoft ASP.NET MVC 5.0 (KB2992080)"

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

Collection Type Guidence

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.