使用PowerShell对接VirusTotal API遇类型缺失,求Add-Type解决方案
Hey there! I’ve dealt with this exact error when working with VirusTotal’s official PowerShell code, so I can help you resolve it quickly.
The error pops up because the [System.Security.Cryptography.ProtectedData] class lives in the System.Security .NET assembly, which isn’t always automatically loaded in PowerShell—especially in older versions or constrained environments.
To fix this, you just need to explicitly load the assembly at the very start of your script, before any code that references ProtectedData. Add this line:
Add-Type -AssemblyName System.Security
This tells PowerShell to load the necessary assembly that contains the ProtectedData type, which the VirusTotal script uses to securely store and retrieve your API key. Once you add this line, your code should run without that type-finding error.
内容的提问来源于stack exchange,提问作者Sam

