check the string is Base64 encoded in PowerShell
问题 I am using PowerShell to make a condition selection, need to judge whether the string is Base64 encoded, What is the easiest and most direct way? if ($item -is [?base64]) { # handle strings or characters } 回答1: The following returns $true if $item contains a valid Base64-encoded string , and $false otherwise: try { $null=[Convert]::FromBase64String($item); $true } catch { $false } The above uses System.Convert.FromBase64String to try to convert input string $item to the array of bytes it