Created
June 11, 2024 07:24
-
-
Save nohwnd/ecddf918a1c2725b329cdcb825dd471b to your computer and use it in GitHub Desktop.
Avoid unapproved verb warning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function HurrDurr-Item2 { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment