Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Created June 11, 2024 07:24
Show Gist options
  • Save nohwnd/ecddf918a1c2725b329cdcb825dd471b to your computer and use it in GitHub Desktop.
Save nohwnd/ecddf918a1c2725b329cdcb825dd471b to your computer and use it in GitHub Desktop.
Avoid unapproved verb warning
Get-Module unapproved-verb, warning | Remove-Module
# this won't warn, we mutated the approved verbs list
Import-Module $PSScriptRoot\unapproved-verb.psm1
# we clean up after ourselves in few seconds
Write-Host waiting...
Start-Sleep -Seconds
# this will warn again
Import-Module $PSScriptRoot\warning.psm1
function HurrDurr-Item {
}
$verbs = [System.Management.Automation.VerbsCommon].Assembly.GetTypes() | where { $_.Name -like "*verbs" }
$validVerbs = $verbs.GetField("s_validVerbs", [System.Reflection.BindingFlags]'Static,NonPublic')
$dict = $validVerbs.GetValue($null)
$dict["HurrDurr"] = $true;
Add-Type -TypeDefinition "
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
public static class DSBResetMe {
private static Task s_task;
public static void Reset(int timeoutMs, string key, Dictionary<string, bool> verbs) {
s_task = Task.Run(async () => {
await Task.Delay(timeoutMs);
try {
if (verbs.ContainsKey(key)) {
verbs.Remove(key);
}
} catch {}
});
}
}
"
[DSBResetMe]::Reset(3000, "HurrDurr", $dict)
Export-ModuleMember -Function HurrDurr-Item
function HurrDurr-Item2 {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment