【问题标题】:Cannot find cert: drive or Certificate Provider via Powershell无法通过 Powershell 找到证书:驱动器或证书提供程序
【发布时间】:2019-01-27 23:42:06
【问题描述】:

由于某种原因,我安装的 Windows 10/Powershell 5.0 似乎缺少Certificate Provider。似乎我什至没有 Microsoft.PowerShell.Security 模块,默认情况下应该与 powershell 一起安装并包含证书提供程序。这是我在运行 Get-Module 时得到的(我前段时间添加了 post-git,也许我这样做时搞砸了?):

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script     0.7.1      posh-git                            {Add-PoshGitToProfile, Add-SshKey, Enable-GitColors, Get-A...
Script     1.2        PSReadline                          {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PS...

这是我运行 Get-PSProvider 时得到的结果:

Name                 Capabilities                                      Drives
----                 ------------                                      ------
Registry             ShouldProcess, Transactions                       {HKLM, HKCU}
Alias                ShouldProcess                                     {Alias}
Environment          ShouldProcess                                     {Env}
FileSystem           Filter, ShouldProcess, Credentials                {C, D, E}
Function             ShouldProcess                                     {Function}
Variable             ShouldProcess                                     {Variable}

我是否可以重新安装 PowerShell 或将此提供程序/驱动器添加到我的构建中而无需完全重新安装 Windows?我的机器似乎发生了一些非常可疑的事情,如果不是绝对必要的话,我真的不想完全重新安装。

【问题讨论】:

  • 我得到了和你一样的模块和提供者,这很正常,你得到的是你做ls cert:吗?
  • 还有这个:Get-PSProvider -PSProvider Certificate | fl * ?
  • Get-PSProvider -PSProvider Certificate | fl * Get-PSProvider : Cannot find a provider with the name 'Certificate'. At line:1 char:1 + Get-PSProvider -PSProvider Certificate | fl * + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Certificate:String) [Get-PSProvider], ProviderNotFoundException + FullyQualifiedErrorId : ProviderNotFound,Microsoft.PowerShell.Commands.GetPSProviderCommand
  • ls cert: ls : Cannot find drive. A drive with the name 'cert' does not exist. At line:1 char:1 + ls cert: + ~~~~~~~~ + CategoryInfo : ObjectNotFound: (cert:String) [Get-ChildItem], DriveNotFoundException + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
  • 您应该能够在您的 Windows 安装上运行恢复来解决问题。

标签: powershell windows-10 certificate powershell-5.0


【解决方案1】:

我来找同样的问题。

我的问题是 PSModulePath 环境变量中没有正确的路径。

【讨论】:

  • 需要什么路径?供应商在哪里?
  • @DarenThomas 对于证书,它将是 PKI 模块。最好的办法是从环境变量中读取模块路径,然后复制到会话模块路径变量中,如下所示: $env:PSModulePath = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine')
【解决方案2】:

在安装 MSI 期间运行自定义 powershell 操作时,我遇到了同样的错误。 Maco1717 的回答为我指明了正确的方向。当 Powershell 在安装程序上下文中运行时,PSModulePath 是不同的。解决方法是在脚本开头从环境变量中加载正确的路径:

$env:PSModulePath = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine')

【讨论】:

    猜你喜欢
    • 2013-06-30
    • 2012-10-26
    • 2013-08-13
    • 2021-08-25
    • 1970-01-01
    • 2022-07-06
    • 2014-09-16
    • 2017-09-16
    • 2016-07-15
    相关资源
    最近更新 更多