You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

创建PSADPasswordCredential对象时遇类型未找到错误,如何解决?

解决PSADPasswordCredential类型找不到的问题

方案一:改用Az模块原生Cmdlet(推荐)

手动创建PSADPasswordCredential对象的方式已不推荐,Az模块提供了专门的Cmdlet管理应用凭据,无需手动处理类型加载问题:

$Password = ConvertTo-SecureString "SuperStrongPassword" -AsPlainText -Force
# 替换<你的应用ID>为实际Azure AD应用程序ID
New-AzADAppCredential -ApplicationId "<你的应用ID>" -Password $Password -StartDate (Get-Date) -EndDate (Get-Date -Year 2024)

方案二:更新并重新加载Az模块

若必须使用原代码,先确保Az模块为最新版本,旧版本可能缺失该类型:

  1. 更新Az模块:
Update-Module -Name Az -Force -AllowClobber
  1. 卸载并重新导入相关模块:
Remove-Module Az.Accounts, Az.Resources -Force
Import-Module Az.Accounts, Az.Resources -Force

方案三:手动加载对应程序集

更新模块后仍找不到类型时,可手动定位并加载包含PSADPasswordCredential的程序集:

  1. 查找程序集路径:
$assemblyPath = (Get-Module Az.Resources).ModuleBase + "\Microsoft.Azure.PowerShell.Cmdlets.Resources.dll"
  1. 加载程序集:
Add-Type -Path $assemblyPath

之后再执行原代码即可。

方案四:检查PowerShell版本兼容性

确保使用PowerShell 5.1或更高版本(Az模块支持PowerShell 7.x,避免使用过低版本的PowerShell)。

内容的提问来源于stack exchange,提问作者InteXX

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 14:35:06