using namespace System.Management.Automation | |
using namespace System.Management.Automation.Runspaces | |
using namespace System.Collections | |
using namespace System.Collections.Generic | |
using namespace System.Text | |
using namespace System.Xml | |
using namespace System.IO | |
$ErrorActionPreference = 'Stop' | |
$SCRIPT:RunspaceFormats = [Runspace]::DefaultRunspace.InitialSessionState.Formats |
function inspectRunes { | |
<# | |
.synopsis | |
minimal sugar to see codepoints | |
.EXAMPLE | |
$Str1 = '🐒' | |
$str1 | inspectRunes.prof | |
#> | |
param( | |
# default will replace control chars to text. ie: You can pipe it safely |
using namespace System | |
using namespace System.Linq | |
using namespace System.Collections | |
using namespace System.Collections.Generic | |
using namespace System.Management.Automation | |
using namespace System.Management.Automation.Language | |
using namespace System.Reflection | |
# Hey person reading this! Don't do this, alright? You'll have a bad time. ty |
This is to try and document the behaviour around PowerShellGet/PSResourceGet code signing publisher behaviour.
The following code can be used to set up this scenario. This must be run as an administrator in Windows PowerShell.
Note: PowerShell uses implicit remoting for the New-SelfSignedCertificate
which breaks the constains serialization. You must run this on Windows PowerShell.
class ConstrainedVariableInterpolation : System.Management.Automation.Language.AstVisitor { | |
hidden [Hashtable] $Property | |
[System.Collections.Generic.List[PSCustomObject]] $Result | |
hidden [System.Management.Automation.Language.Ast] $Ast | |
[System.Management.Automation.Language.AstVisitAction] CheckForPostAction([System.Management.Automation.Language.Ast] $ast, [System.Management.Automation.Language.AstVisitAction] $action) | |
{ | |
throw 'CheckForPostAction not supported' | |
} | |
This is always my answer to all those "compile your .ps1" solutions that are floating around. Why would you wrap your PowerShell in an exe and some custom host?
Just paste this header on the top of your PowerShell script, and then before you share it, rename it with the .cmd
extension. While you're writing, it's a nice syntax-highlighted PowerShell script, and when you rename it, *poof*
it's double-clickable. Drop it in the PATH and you can execute it from the Run dialog or from PowerShell, batch, whatever.
Because there are still people around who actually use CMD, I've updated it to show how to handle passing parameters.
A couple of notes:
- It runs with
ExecutionPolicy
unrestricted because if you're still using CMD you probably haven't configured your ExecutionPolicy - It uses
-NoProfile
to make sure the environment is the same on everyone's PC... - It only creates
function :: {}
because that allows us to ignore the :: on the first line
using namespace System.Collections.Generic; using namespace System.Text | |
Add-Type -TypeDefinition ' | |
using System; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
public class WindowTools | |
{ | |
public delegate bool EnumWindowsProc(IntPtr hWnd, int lParam); |