Maybe
Maybe

Reputation: 995

Print success/finished message in user's own language

In PowerShell, I'd like to print a message to the user that indicates the script finished without issue. I know there's several localization-based functions, but instead of having to provide a list of machined translated strings, it would be better there was an internal list of common messages I could pull from (from .NET or wherever else) that would be locale-dependent. Or, maybe a built-in command that prints a success message.

Upvotes: 0

Views: 218

Answers (1)

Maybe
Maybe

Reputation: 995

Answer provided by Jeroen Mostert from the comment above:

[ComponentModel.Win32Exception]::new(0).Message should give you whatever the local equivalent of "The operation completed successfully" is.

(I'm not sure why he didn't submit it as an answer.)

There are many more messages too. I've filtered out the 'Unknown errors' from the first 20,000: https://pastebin.com/F9jQUHMt

Command used:

$m = New-Object 'Collections.Generic.Dictionary[[string],[int]]'
(0..20000).ForEach({ try{$m.add((([ComponentModel.Win32Exception]::new($_).
Message -join ' ') -replace '\s\s+',' '), $_)} catch{} })
$m.Keys.Where({$_ -notlike 'Unknown error *'}).ForEach({ "[$($m.Item($_))] $_" })

I used a dictionary so that only the first occurrence of an error message would be added along with its index. And, as far as I can tell, 15864 is the last non-unknown error.

Upvotes: 1

Related Questions