2

I want to port an existing PowerShell script written in PowerShell 5.1 to PowerShell 7.1. However it seems I can't create objects of type [Windows.Security.Credentials.PasswordCredential] as the type can not be found.

Having a look at the registry tells me this class is stored at the following locations:

  • C:\Windows\System32\vaultcli.dll
  • C:\Windows\SysWOW64\vaultcli.dll

But adding these DLLs to my script in PS 7.1 fails:

PS C:\Users\xxx> Add-Type -Path "C:\Windows\System32\vaultcli.dll"        
Add-Type: Bad IL format. The format of the file 'C:\Windows\System32\vaultcli.dll' is invalid.
PS C:\Users\xxx> Add-Type -Path "C:\Windows\SysWOW64\vaultcli.dll"
Add-Type: Bad IL format. The format of the file 'C:\Windows\SysWOW64\vaultcli.dll' is invalid.

Checking the related codebase parameter in PowerShell 5.1 returns the following:

PS C:\Users\xxx> [Windows.Security.Credentials.PasswordVault].Assembly.CodeBase
file:///C:/WINDOWS/system32/WinMetadata/Windows.Security.winmd

How can I correctly add a reference to this type?

ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
GuidoT
  • 280
  • 1
  • 12
  • 1
    It *might* be because that's a WinRT assembly - see https://learn.microsoft.com/en-us/uwp/api/windows.security.credentials.passwordcredential?view=winrt-20348#applies-to. There's a workaround here that might help - https://github.com/PowerShell/PowerShell/issues/13042#issuecomment-653357546 – mclayton Aug 23 '21 at 12:36
  • I came upon this post after searching and finding your post. Maybe this can help? https://stackoverflow.com/questions/29103238/accessing-windows-credential-manager-from-powershell – Bbb Jul 15 '22 at 18:13

0 Answers0