using namespace System.Collections.Generic
$example = 9, 4, 3
[List[int]]::new( [int[]]$example ) - I had to type it as an
[int[]]
| <html><body> | |
| <table class="cols-3"> | |
| <tr> | |
| <th>Company</th> | |
| <th>Contact</th> | |
| <th>Country</th> | |
| </tr> | |
| <tr> | |
| <td>Alfreds Futterkiste</td> | |
| <td>Maria Anders</td> |
| let | |
| Path_Xlsx = "c:\data\workbook.xlsx", | |
| Summary = [ | |
| // [1] using "enter-data" saves a table as json like this | |
| b64_str = "i45WSkosUoqNBQA=", | |
| bytes = Binary.FromText( b64_str, BinaryEncoding.Base64), | |
| bytes_decompressed = Binary.Decompress( bytes, Compression.Deflate), | |
| final_json_str = Text.FromBinary( bytes_decompressed, TextEncoding.Utf8 ), | |
| // [2] converting some binary file to base64 |
| #Requires -Version 7 | |
| using namespace System.Collections.Generic | |
| using namespace System.Text | |
| using namespace System.Text.Json | |
| using namespace System.Text.Json.Serialization | |
| using namespace System.Linq | |
| $assembly = Add-type -AssemblyName System.Text.Json -PassThru -ea 'stop' | |
| <# |
| void updateHunger() { | |
| // applied about every 1 second? | |
| curDrain = GetCurrentDrain(); | |
| energy -= curDrain // but clamps to keep it >= 0 | |
| newTier = GetTier( energy ) | |
| if ( newTier != curTier ) { | |
| SetTier( newTier ) | |
| } | |
| } |
| # Assumes pwsh7 | |
| # tip: pwsh 7 added overloads | |
| $StrIn = 'Г¶' | |
| $bytes = [Text.Encoding]::GetEncoding(1252).GetBytes( $StrIn ) | |
| $Bytes = [Text.Encoding]::GetEncoding('utf-8').GetString( $bytes ) | |
| # and also | |
| $StrIn.EnumerateRunes | Ft -auto |
| function NewUser { | |
| <# | |
| .synopsis | |
| Create a new user with a name. Any "blank" values will fallback with a default value | |
| .DESCRIPTION | |
| If you use ValidateIfNotSomething, invalid or missing values throws. | |
| - Sometimes you want the command that always works, with a fallback value | |
| - $null, empty string to count as blank |