Powershell日期类型找不到

Powershell日期类型找不到,powershell,types,Powershell,Types,我正在尝试使用PowerShell连接virustotal API,代码来自virustotal网站,我收到“找不到类型[System.Security.Cryptography.ProtectedData]”错误消息 代码如下 function Get-VTApiKey { [CmdletBinding()] Param([String] $vtFileLocation = $(Join-Path $env:APPDATA 'virustotal.bin')) if (

我正在尝试使用PowerShell连接virustotal API,代码来自virustotal网站,我收到“找不到类型[System.Security.Cryptography.ProtectedData]”错误消息

代码如下

function Get-VTApiKey {
    [CmdletBinding()]
    Param([String] $vtFileLocation = $(Join-Path $env:APPDATA 'virustotal.bin'))
    if (Test-Path $vtfileLocation) {
        $protected = [System.IO.File]::ReadAllBytes($vtfileLocation)
        $rawKey = [System.Security.Cryptography.ProtectedData]::Unprotect($protected, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)

        return [System.Text.Encoding]::Unicode.GetString($rawKey)
    } else {
        throw "Call Set-VTApiKey first!"
    }
}
经过研究,我发现我需要使用addtype来添加一些东西来解决这个问题。有什么建议需要补充吗? 提前感谢。

将程序集列为
System.Security
。因此,您需要:

Add-Type -AssemblyName System.Security

您可能还需要考虑一些其他密码特性(<)/P>的代码> St.Cype < /C>。 将程序集列为

System.Security
。因此,您需要:

Add-Type -AssemblyName System.Security

您可能还需要考虑一些其他密码特性(<)/P>的代码> St.Cype < /C>。


你确定这是导致你出错的代码吗?您说错误是关于
ProtectedData
,但是文本
ProtectedData
没有出现在您的代码中的任何地方。我相信这就是$protected的类型。尝试将Add Type-AssemblyName System.Core添加到您的代码Hi Joe抱歉,发布了错误的代码,更新了邮件您确定这是导致错误的代码吗?您说错误是关于
ProtectedData
,但是文本
ProtectedData
没有出现在您的代码中的任何地方。我相信这就是$protected的类型。尝试将Add Type-AssemblyName System.Core添加到您的代码Hi Joe抱歉发布了错误的代码,更新了帖子